[Catalyst] Relationship layout

Will Smith willbelair at yahoo.com
Mon Oct 3 16:28:49 CEST 2005


Thanks a lot for your instruction.

Dan Boger <perl at peeron.com> wrote:On Mon, Oct 03, 2005 at 07:15:37AM -0700, Will Smith wrote:
> Oh, my bad. Yes, I put it right after the package definition. I
> just pasted in the wrong place. I would re-phrase my question as:
> 
> Once I have this has-many relationship declared, how would I use
> it? And if I have more than one relationship to this one table,
> would I declare the same way?
> 
> Please give me a specific line of instruction.

Well, a really good example can be found here:

http://wiki.class-dbi.com/index.cgi?BeginnersGuide

(look in the relationships section).

In general, you declare the relationships with has_a and has_many, then
when you access those fields, instead of getting a scalar value, you get
CDBI objects back:

package Music::Artist;
__PACKAGE__->has_many(cds => 'Music::CD');
...

package Music::CD;
__PACKAGE__->has_a(artist => 'Music::Artist');
...

$artist = $cd->artist; # returns a Music::Artist object, for the artist of that CD.
@cds = $artist->cds; # returns an array of Music::CD objects

(code written in an email client should never be executed).

HTH! I'm sure the CDBI wiki and list would be able to explain it better
though.

Dan

-- 

_______________________________________________
Catalyst mailing list
Catalyst at lists.rawmode.org
http://lists.rawmode.org/mailman/listinfo/catalyst


		
---------------------------------
Yahoo! for Good
 Click here to donate to the Hurricane Katrina relief effort. 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.rawmode.org/pipermail/catalyst/attachments/20051003/d9e22c02/attachment.htm


More information about the Catalyst mailing list