[Dbix-class] using HasMany with object references

Matt S Trout dbix-class at trout.me.uk
Sat Dec 3 02:36:53 CET 2005


On Fri, Dec 02, 2005 at 07:04:41PM -0600, Justin Guenther wrote:
> I'm trying to use DBIx::Class to store some existing classes in a database.
> I think I have all my relationships set up correctly, and I ran into an
> issue with HasMany's add_to_* methods. It is expecting a hashref of values
> to create the new object, but the way my existing classes are set up it
> would be much easier to simply pass it an already-created object reference.
> Is there a way to do this?

Assuming the other side has a belongs_to set up, just calling

$foo_obj->belongs_to_rel($obj_which_has_many_foo);

should do the trick.

-- 
     Matt S Trout       Offering custom development, consultancy and support
  Technical Director    contracts for Catalyst, DBIx::Class and BAST. Contact
Shadowcat Systems Ltd.  mst (at) shadowcatsystems.co.uk for more information

 + Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +



More information about the Dbix-class mailing list