[Catalyst] Relationship layout

Dan Boger perl at peeron.com
Mon Oct 3 16:25:18 CEST 2005

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:


(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



More information about the Catalyst mailing list