[Dbix-class] How to bring existing objects together?

Tilman Baumann tilman.baumann at collax.com
Mon Dec 12 17:57:26 CET 2005


Hi,

i have two tables. Product may have a license related. (license_id on
table license)

I like to add a existing product object to a license.
I guessed i can do something like this:

$license->add_to_products($product);
Where $product is a instance of LicServ::License.

But this does not work because add_to_products wants a HASH ref.

Is there a nicer way to make such relations without seting the foreign
key on the product object to the primary key of the license object?
like this:
$product->license_id($license->id)

Well add_something is not what i want to do. So i see why this does not
work. :)
But is there a way to bring two objects together which have defined
relationships?


My packages look like this:
package LicServ::License;
LicServ::License->table('license');
LicServ::License->add_columns(qw(id created assigned));
LicServ::License->set_primary_key('id');
LicServ::License->has_many('products' => 'LicServ::Product',
{'foreign.license_id' => 'self.id'});


package LicServ::Product;
LicServ::Product->table('product');
LicServ::Product->add_columns(qw(id activated created type description
duration arcode license_id));
LicServ::Product->set_primary_key('id');



-- 
Tilman Baumann
Software Developer
Collax GmbH . Boetzinger Straße 60 . 79111 Freiburg . Germany

p: +49 (0) 761-4514-836
f: +49 (0) 761-4563-793





More information about the Dbix-class mailing list