DAO機能を持つBeanである2つのCFCがあります。子 cfc が親を拡張する継承を設定しました。
両方のオブジェクトの構造は同じです。関数: init、read などおよびプロパティ: ID など
子オブジェクトを作成するときに ID を渡します。ID はデータを読み取り、親の外部キーの parentID を取得し、適切なパラメーターを指定して Super.init() を呼び出します。
私の予期しない結果は次のとおりです。子のIDとparentIDの両方が同じで、オブジェクトが返されたときのparentID値です。childs variables.ID は、super 呼び出しの後に上書きされます。変数スコープは両方からアクセスできると想定しているため、親が変数.IDを設定すると、子変数.IDが上書きされます。ID に別の名前を付けずにこれを回避できますか?
親オブジェクトの読み取り関数は実行されないようです。たとえば、親の読み取り関数の名前を「read2」に変更すると、関数が実行されます。また、関数が共有スコープに存在するため、子の読み取り関数が実行されていると思われます。
同じ cfc 構造を維持し、この機能を期待どおりに動作させる方法はありますか?
前もって感謝します。
<cfcomponent accessors="true" extends="Custom" output="false">
<cfproperty name="ID" type="numeric" />
<cfproperty name="listID" type="numeric" />
<cfproperty name="customfieldID" type="numeric" />
<cfscript>
variables.dsn = '';
</cfscript>
<cffunction name="init" access="public" output="false" returntype="ListCustom">
<cfargument name="dsn" type="string" required="true" />
<cfargument name="ID" type="numeric" required="true" />
<cfargument name="listID" type="numeric" required="false" default="0" />
<cfargument name="customFieldID" type="numeric" required="false" default="0" />
<cfscript>
variables.dsn = arguments.dsn;
variables.ID = arguments.ID;
variables.listID = arguments.listID;
variables.customFieldID = arguments.customFieldID;
if (variables.ID){
read();
if (variables.customFieldID){
Super.init(dsn=variables.dsn,ID=variables.customfieldID);
}
}
</cfscript>
<cfreturn this />
</cffunction>
<cffunction name="read" access="private" output="false" returntype="void">
<cfquery name="local.q" datasource="#variables.dsn#">
SELECT customfieldID, listID
FROM listCustomFields
WHERE ID = <cfqueryparam value="#variables.ID#" cfsqltype="cf_sql_integer">
</cfquery>
<cfif local.q.recordcount>
<cfset variables.listID = local.q.listID />
<cfset variables.customFieldID = local.q.customFieldID />
</cfif>
</cffunction>
<cfcomponent accessors="true" output="false">
<cfproperty name="ID" type="numeric" />
<cfproperty name="fieldName" type="string" />
<cfscript>
variables.dsn = '';
</cfscript>
<cffunction name="init" access="public" output="false" returntype="Custom">
<cfargument name="dsn" type="string" required="true" />
<cfargument name="ID" type="numeric" required="true" />
<cfargument name="fieldName" type="string" required="false" default="" />
<cfscript>
variables.dsn = arguments.dsn;
variables.ID = arguments.ID;
variables.fieldName = arguments.fieldName;
if (variables.ID){
read();
}
</cfscript>
<cfreturn this />
</cffunction>
<cffunction name="read" access="private" output="false" returntype="void">
<cfquery name="local.q" datasource="#variables.dsn#">
SELECT fieldName
FROM CustomField
WHERE ID = <cfqueryparam value="#variables.ID#" cfsqltype="cf_sql_integer">
</cfquery>
<cfif local.q.recordcount>
<cfset variables.fieldName = local.q.fieldName />
</cfif>
</cffunction>