<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Matt S Trout schrieb:
<blockquote cite="mid20051212195103.GA8551@central.redice.net"
type="cite">
<pre wrap="">On Mon, Dec 12, 2005 at 05:57:26PM +0100, Tilman Baumann wrote:
</pre>
<blockquote type="cite">
<pre wrap="">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?
</pre>
</blockquote>
<pre wrap=""><!---->
If you add a belongs_to rel from product to license called 'license', you'll
get a $product->license accessor for the license object. Then you just call
$product->license($license)
and DBIx::Class will handle it for you.
</pre>
</blockquote>
<br>
Well this would be nice. A bit different than i expected. But it's
logic. ;)<br>
<br>
But i still have a little problem here.<br>
The relation hasn't the same name as the refering column.<br>
Strangely he belongs_to call do not fail. But if i call the
$product->license() function it fails because the fuction is not
defined.<br>
<br>
If i give the relation the same name as the column in the table it
works fine.<br>
I think i have to give a condition too. But this is anythin i do not
understand completely yet.<br>
<br>
I use license_id() now. Thats ok.<br>
<br>
Nevertheless it would be nice if i can give the relation in the other
direction. Like add_to_relname().<br>
Maybe the add_to_relname accessor needs to check if a parameter is of
type Foreign::Class and and do not try to create the object but only
link them toghether.<br>
I find that verry usefull and it's what i first expected.... ;)<br>
<br>
<pre class="moz-signature" cols="72">--
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
</pre>
</body>
</html>