Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8667635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:00:52+00:00 2026-06-12T18:00:52+00:00

I have two CFC’s which are Beans with DAO functions. I have set up

  • 0

I have two CFC’s which are Beans with DAO functions. I have set up inheritance where the child cfc extends the parent.

Both objects have identical structures; Functions: init, read, etc. and Properties: ID, etc.

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.

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?

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.

Is there any way to maintain the same cfc structures and get this functionality to work as expected?

Thanks in advance.

<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>

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T18:00:53+00:00Added an answer on June 12, 2026 at 6:00 pm

    First, both garygilbert and KRC were helpful in pointing me in the right direction. Thank you.

    I gathered the following info:
    Both the child and parent will share the same variables scope, so when assigning a value to the variables.ID in super, the child variables.ID value was overwritten.

    Similarly, the child function read takes precedence over the parent read function due to OO function overwriting.

    My adjusted solution:
    Set a temporary ID that is the child id prior to calling Super functions.
    Being that if I pass the ID to the init function, the read function is called automatically, I wanted to avoid doing this in the parent object because it would still call the child read.
    I call Super.init(dsn) to initialize, then then Super.setID(ID), and finally Super.read(). After the super calls, I restore the initial child ID.

            <cfscript>
            variables.dsn = arguments.dsn;
            variables.ID = arguments.ID;
            variables.listID = arguments.listID;
            variables.customFieldID = arguments.customFieldID;
            if (variables.ID){
                read();
                if (variables.customFieldID){
                    variables.tempID = variables.ID;
                    Super.init(dsn=variables.dsn);
                    Super.setID(variables.customfieldID);
                    Super.read();
                    variables.ID = variables.tempID;
                }
            }
        </cfscript>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two arrays of System.Data.DataRow objects which I want to compare. The rows
I have a group of CFC's that I access from two seperate Applicaiton scopes.
I have two classes (MVC view model) which inherits from one abstract base class.
I have two update panels on a page. And I want to update both
Have two tables say ABC and XYZ and contain one column which data will
I have two different Classes: class X { public int TX1 { get; set;
Have two IBOutlets which won't appear in File's Owner to connect to even though
Have two fields start and end, both are dates, I want to write a
I have two classes which need to be in same xml file. The way
I have two Generic Lists with the same objects Type T within them. For

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.