So I've set up a very simple example.
PARENT
component persistent="true" table="Parent" {
property name="id" column="ParentID" fieldtype="id"
generator="native" setter="false";
property name="Children" singularname="Child" fieldtype="one-to-many"
inverse="true" cfc="Child" fkcolumn="ParentID";
}
CHILD
component persistent="true" table="Child" {
property name="id" column="ChildID" fieldtype="id" generator="native"
setter="false";
property name="Parent" fieldtype="many-to-one" cfc="Parent"
fkcolumn="ParentID";
}
TEST CODE:
oParent = entityNew("Parent");
oChild = entityNew("Child");
oParent.addChild(oChild);
oChild.setParent(oParent);
writeOutput("<br>oParent.hasChild(oChild): " &
oParent.hasChild(oChild));
writeOutput("<br>oChild.hasParent(oParent): " &
oChild.hasParent(oParent));
entitySave(oParent);
EntitySave(oChild);
OUTPUT:
oParent.hasChild(oChild): YES
oChild.hasParent(oParent): NO
What happened? Why doesn't the Child see its Parent? I thought if I
set both sides of the relationship, I won't have these problems?
--
You received this message because you are subscribed to the Google Groups "cf-orm-dev" group.
To post to this group, send email to cf-or...@googlegroups.com.
To unsubscribe from this group, send email to cf-orm-dev+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cf-orm-dev?hl=en.
On Apr 15, 2:03 pm, Bob Silverberg <bob.silverb...@gmail.com> wrote:
> That actually looks to be a bug with the hasParent() method. You are calling
> it incorrectly - the hasParent() method does not accept an argument, because
> there can only be one parent. So your call to oChild.hasParent(oParent) is
> incorrect - it should just be oChild.hasParent(). I believe you'll find if
> you change that they it will return TRUE.
>
> That does not change the fact that your call to oChild.hasParent(oParent)
> did not generate an error, and in fact returned FALSE. That to me is a bug
> and should be reported to Adobe.
>
> Bob
>
>
>
> On Thu, Apr 15, 2010 at 1:43 PM, CoderDave <coderd...@gmail.com> wrote:
> > From what I've read, when in a bidirectional relationship, it's better
> > (Domain Model Integrity) to set both sides of the relationship. To
> > quote this article:
>
> >http://www.briankotek.com/blog/index.cfm/2009/12/16/Bidirectional-Ass...
> > cf-orm-dev+...@googlegroups.com<cf-orm-dev%2Bunsu...@googlegroups.com>
PARENT.cfc
component persistent="true" table="Parent" {property name="Childs" singularname="Child" fieldtype="one-to-many"
property name="id" column="ParentID" fieldtype="id"
generator="native" setter="false";
inverse="true" cfc="Child" fkcolumn="ParentID";// association management method to ensure Domain Model Integrity
public function addChild(oChild) {
// first relate child to this parent
variables.Childs = [arguments.oChild];