Hi Mark,

I was worried that'd be hard to follow...

Here's the relevant bits from the config:

                <package name="sse">

                        <object name="SSE" table="sse" sequence="seq_sse">

                                <id name="sseId" type="numeric"/>


                                <onetomany name="estimateLine" lazy="true">
                                        <link to="sse.EstimateLine" 
column="sseId"/>
                                        <collection type="array"/>
                                </onetomany>

                        </object>

                        <object name="EstimateLine" table="estimateLines"
sequence="seq_estimatelines">

                                <compositeid>
                                        <parentonetomany class="sse.SSE" />
                                        <property name="phaseId" />
                                </compositeid>

                                <property name="phaseId" type="numeric"/>

                        </object>

                </package>

You can put the following code in a .cfm and run it over and over
again without any problems:

<!--- get the parent --->
<cfset sse = transfer.get('sse.SSE',1)/>

<!--- clear it's children --->
<cfset lines = sse.getEstimateLineArray()/>
<cfloop from="1" to="#ArrayLen(lines)#" index="i">
        <cfoutput>deleting line #i#<br></cfoutput>
        <cfset transfer.delete(lines[i])/>
</cfloop>

<!--- create a new child --->
<cfset line = transfer.new('sse.EstimateLine')/>
<cfset line.setParentSSE(sse)/>
<cfset line.setPhaseId(1)/>

<!--- save the child --->
<cfset transfer.save(line)/>

when I use a clone instead by saying:
<cfset sse = transfer.get('sse.SSE',1).clone()/>

It fails if I run this template twice because the sse (parent) doesn't
have the estimateLine (child)) that was added the first time through
so it can't find it to delete it and the insert fails on a pk
constraint. Clearing the cache
before hand makes the estimateLine (child) show up in the sse (parent)
which then allows everything to work fine.

Hopefully that makes sense.

Thanks,
Chris


On Jan 26, 6:23 pm, Mark Mandel <[email protected]> wrote:
> Chris,
>
> I'm trying to follow this.
>
> Could you provide your config file, and some code examples of what you are
> trying to do?
>
> Mark
>
>
>
> On Wed, Jan 27, 2010 at 9:38 AM, achebe <[email protected]> wrote:
> > I'm trying to figure out the proper way to remove all of the children
> > of a parent in a onetomany relationship before adding new children
> > when those children have a composite key containing the
> > parentonetomany.
>
> > The reason I ask is if I get the parent and call transfer.delete() for
> > each of it's children everything works as expected, however if I get a
> > clone of the parent and call transfer.delete() for each of the
> > children the child is not disassociated with the parent unless I call
> > transfer.discard(parent) or child.removeParent() after deleting the
> > child.
>
> > Calling child.removeParent() seems to screw up the cache somehow;
> > things get all screwy unless I call transfer.discard(parent) so I'm
> > guessing I should just toss the parent out of the cache instead of
> > trying to disassociate it.
>
> > Should I not be trying to remove children from a clone or should I
> > just discard the clone from the cache after I remove the children and
> > not worry about it?
>
> > Thanks,
> > Chris
>
> > --
> > Before posting questions to the group please read:
>
> >http://groups.google.com/group/transfer-dev/web/how-to-ask-support-qu...
>
> > You received this message because you are subscribed to the Google Groups
> > "transfer-dev" group.
> > To post to this group, send email to [email protected]
> > To unsubscribe from this group, send email to
> > [email protected]
> > For more options, visit this group at
> >http://groups.google.com/group/transfer-dev?hl=en
>
> --
> E: [email protected]
> T:http://www.twitter.com/neurotic
> W:www.compoundtheory.com
>
> Hands-on ColdFusion ORM Training @ cf.Objective() 
> 2010www.ColdFusionOrmTraining.com/

-- 
Before posting questions to the group please read:
http://groups.google.com/group/transfer-dev/web/how-to-ask-support-questions-on-transfer

You received this message because you are subscribed to the Google Groups 
"transfer-dev" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/transfer-dev?hl=en

Reply via email to