On 12/22/06 1:40 PM, Chris Campise wrote: > package My::DB::Parent; ... > relationships => > [ > child => > { > class => 'My::DB::Child', > column_map => { parent_id => 'parent_id' }, > type => 'one to many', > },
You have that listed as "one to many", but the name is singular. Do you expect there to be one child or many children? Anyway, given the "one to many" relationship, this call is not doing what you think: > $p->child(notes => "These are some child notes"); Looking at the method map for the OneToMany relationship: http://search.cpan.org/dist/Rose-DB-Object/lib/Rose/DB/Object/Metadata/Relat ionship/OneToMany.pm#METHOD_MAP and following it to the documentation for the get_set_on_save method created by default for such a relationship: http://search.cpan.org/dist/Rose-DB-Object/lib/Rose/DB/Object/MakeMethods/Ge neric.pm#objects_by_key it says this about the arguments passed to such a method: "If passed a single argument of undef, the list of objects is set to undef, causing it to be reloaded the next time the method is called with no arguments. (Pass a reference to an empty array to cause all of the existing objects to be deleted from the database when the parent is saved.) Otherwise, the argument(s) must be a list or reference to an array containing items in one or more of the following formats: * An object of type class * A reference to a hash containing method name/value pairs. * A single scalar primary key value" In light of that, look again at this call: $p->child(notes => "These are some child notes"); and you'll see that it's actually being interpreted as passing two primary key values: "notes" and "These are some child notes". MySQL, being ever-so-helpful, accepts those values right into its child_id INTEGER AUTO_INCREMENT column, then silently ignores them and uses an auto-incremented value instead. Thus, you get the following: > But there are two Child rows being inserted, and neither have the child.notes > field populated [...] > > Child Table: > child_id parent_id notes > 00000000001 00000000001 > 00000000002 00000000001 So, you have to do two things here. First, decide whether or not that relationship is really "one to many". Assuming it is, you can set a single child value by choosing one of the other two possible formats: * An object of type class * A reference to a hash containing method name/value pairs. Example (with renamed relationship, child -> children): $p->children({ notes => "These are some child notes" }); $p->save; That should work the way you expect. -John ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ Rose-db-object mailing list Rose-db-object@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rose-db-object