[Catalyst] Relationship layout

Will Smith willbelair at yahoo.com
Wed Oct 5 06:47:44 CEST 2005

Thanks Dan,
I follow the instruction and have all work nicely. I need to ad one line to the has_a relationship to make it work. Anyway, I still get some problem:
running the app under the built-in http, I cannot use perl script. So I need to have data display on the template. So if I have:
my $cd = music::M::CDBI::Cd->search(title=>'Blue');
In a perl script I could do : 
print "The CD: ",$cd->title," written by the: ",$cd->artistid->name,"\n";
But, how could I do the same thing on a template? And just to confirm this: the has_a,has_many relationship are defined in the myapp::M::CDBI::Mytable NOT IN myapp::C::CDBI::Mytable nor Myapp.pm
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:


(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



Catalyst mailing list
Catalyst at lists.rawmode.org

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/20051004/5a7b2126/attachment.htm

More information about the Catalyst mailing list