Note that there are some explanatory texts on larger screens.

plurals
  1. POInherited CFC not populating
    primarykey
    data
    text
    <p>I have two CFC's which are Beans with DAO functions. I have set up inheritance where the child cfc extends the parent.</p> <p>Both objects have identical structures; Functions: init, read, etc. and Properties: ID, etc. </p> <p>When I create the child object, I pass an ID, which reads the data, getting the foreign key parentID for the parent and then Super.init() is called with appropriate parameters.</p> <p>My unexpected results are: Both the ID for the child and the parentID are the same and are the parentID value when the object is returned. The childs variables.ID is overwritten after the super call. I assume that the variables scope is accessible by both, so when parent sets variables.ID it overwrites the child variables.ID. Can this be avoided without naming IDs differently?</p> <p>The read function of the parent object does not appear to execute. If I rename the parents read function 'read2' for example, the function executes. I also suspect that the functions reside in a shared scope and therefore the childs read function is executing.</p> <p>Is there any way to maintain the same cfc structures and get this functionality to work as expected?</p> <p>Thanks in advance.</p> <pre><code>&lt;cfcomponent accessors="true" extends="Custom" output="false"&gt; &lt;cfproperty name="ID" type="numeric" /&gt; &lt;cfproperty name="listID" type="numeric" /&gt; &lt;cfproperty name="customfieldID" type="numeric" /&gt; &lt;cfscript&gt; variables.dsn = ''; &lt;/cfscript&gt; &lt;cffunction name="init" access="public" output="false" returntype="ListCustom"&gt; &lt;cfargument name="dsn" type="string" required="true" /&gt; &lt;cfargument name="ID" type="numeric" required="true" /&gt; &lt;cfargument name="listID" type="numeric" required="false" default="0" /&gt; &lt;cfargument name="customFieldID" type="numeric" required="false" default="0" /&gt; &lt;cfscript&gt; 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); } } &lt;/cfscript&gt; &lt;cfreturn this /&gt; &lt;/cffunction&gt; &lt;cffunction name="read" access="private" output="false" returntype="void"&gt; &lt;cfquery name="local.q" datasource="#variables.dsn#"&gt; SELECT customfieldID, listID FROM listCustomFields WHERE ID = &lt;cfqueryparam value="#variables.ID#" cfsqltype="cf_sql_integer"&gt; &lt;/cfquery&gt; &lt;cfif local.q.recordcount&gt; &lt;cfset variables.listID = local.q.listID /&gt; &lt;cfset variables.customFieldID = local.q.customFieldID /&gt; &lt;/cfif&gt; &lt;/cffunction&gt; </code></pre> <p></p> <pre><code>&lt;cfcomponent accessors="true" output="false"&gt; &lt;cfproperty name="ID" type="numeric" /&gt; &lt;cfproperty name="fieldName" type="string" /&gt; &lt;cfscript&gt; variables.dsn = ''; &lt;/cfscript&gt; &lt;cffunction name="init" access="public" output="false" returntype="Custom"&gt; &lt;cfargument name="dsn" type="string" required="true" /&gt; &lt;cfargument name="ID" type="numeric" required="true" /&gt; &lt;cfargument name="fieldName" type="string" required="false" default="" /&gt; &lt;cfscript&gt; variables.dsn = arguments.dsn; variables.ID = arguments.ID; variables.fieldName = arguments.fieldName; if (variables.ID){ read(); } &lt;/cfscript&gt; &lt;cfreturn this /&gt; &lt;/cffunction&gt; &lt;cffunction name="read" access="private" output="false" returntype="void"&gt; &lt;cfquery name="local.q" datasource="#variables.dsn#"&gt; SELECT fieldName FROM CustomField WHERE ID = &lt;cfqueryparam value="#variables.ID#" cfsqltype="cf_sql_integer"&gt; &lt;/cfquery&gt; &lt;cfif local.q.recordcount&gt; &lt;cfset variables.fieldName = local.q.fieldName /&gt; &lt;/cfif&gt; &lt;/cffunction&gt; </code></pre> <p></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload