On Jan 9, 2008 20:02, John Siracusa <[EMAIL PROTECTED]> wrote: > In the meantime, you can always express more explicitly the operations > you intend to perform. For example: > > $product = My::DB::Product->new( > name => $^T, > add_prices => > [ > { price => 3.60, region => 'uk' }, > { price => 7.00, region => 'us' }, > ]); > > $product->save;
Thanks for that suggestion, something that I didn't think about. The add_ prefix doesn't look that nice in the constructor. As we would probably need to use it everywhere we create new objects for inserting into the database, we will probably override the constructor in our base class to to call the add methods instead of the 'get_set_on_save' method for both 'one to many' and 'many to many' relationships. The only problem is that our code manipulates the object before deciding to save the data (e.g. does our own additional validation). With this I can't find any way of getting to the objects that will be added, as $product->prices returns the empty list. my $product = My::DB::Product->new( name => $^T, add_prices => [ { price => 3.60, region => 'uk', }, { price => 7.00, region => 'us', }, ], ); use Data::Dumper; print Dumper [$product->prices]; If the add_on_save method is called with no parameters, then it might make sense for this to return a list of objects that will be added (if one wants to ensure that an empty list isn't passed to this method, then an arrayref could be passed instead). I still think the get_set_on_save method should return both what is already in the database (unless the object isn't in the db, the primary key isn't set and the column type is serial), along with those that are going to be in the database when saved. Thanks Curon ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace _______________________________________________ Rose-db-object mailing list Rose-db-object@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rose-db-object