component persistent="true"
{
property name="ParentId" fieldtype="id" generator="increment" type="numeric";
property name="ParentName";
property name="Children" fieldtype="one-to-many" cfc="Child" fkcolumn="ParentId" cascade="all" type="struct" singularname="Child" structkeycolumn="ChildName" structkeytype="string" inverse="true";
}
component persistent="true"
{
property name="ChildId" fieldtype="id" generator="increment" type="numeric";
property name="ChildName";
property name="Parent" fieldtype="many-to-one" cfc="Parent" fkcolumn="ParentId";
}
<cfscript>
Parent = new Parent();
Parent.setParentName("Bob");
Child = new Child();
Child.setChildName("Daniel");
Child.setParent(Parent);
EntitySave(Parent);
ormFlush();
</cfscript>
<cfscript>
Parent = new Parent();
Parent.setParentName("Bob");
Child = new Child();
Child.setChildName("Daniel");
Child.setParent(Parent);
EntitySave(Parent);
EntitySave(Child);
ormFlush();
</cfscript>
--
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.
--
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.
This method is generated for one-to-many and many-to-many relationships. The method adds the given object to the association collection (array or struct) of the component. For a bidirectional relationship, this method does not set the association on the other end."
Hence, you have to setChild()/setParent() on both sides. You have to look closely, as it's *very* easy to miss.
--
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.
Here's a question:If you have a bi-directional relationship, is there ever a time when you would only want to set one side of the relationship? Is there a use case for doing that, or would you always end up doing:Child.setParent(Parent);Parent.setChild(Child);
If there's no reason to ever set just one side, then would this be a good enhancement request for cf orm? ColdFusion is already creating methods for us for setXXX(), addXXX() and removeXXX() when we create a relationship via a property, so would it be a good idea to have those methods that are created be smart enough to satisfy both sides of the relationship if it is a bi-directional relationship?
Without that we're going to end up having to override all of our setters, adders and removers on these relationships ourselves.
entitySave(child); by adding cascade="save-update" to your many-to-one relationship on the child object