[Catalyst] DBIx::Class and Catalyst - Trying to make sense of it all.

Leanan Sidhe the.leanan.sidhe at gmail.com
Sun Sep 28 15:15:25 BST 2008


First, I apologize for the completely noob tone of this email.  I've read
through the perl docs for DBIx::Class, and various Catalyst parts, but I'm
having problems understanding how DBIx::Class stuff is slightly different in
Catalyst.

For example, in the DBI docs, I constantly see the following:

$schema->resultset('table_name')->search(....);

in Catalyst, this seems to be
$c->model('table_model_package')->search(....);

I get that and it's not too rough.

But then where I get hung up is that I have a few table relationships I want
to query.  Say I have the following tables / relationships:

users:
  user_id
  user_name
  pass

cards:
  card_id
  card_name
  card_description
  set_id

sets:
  set_id
  set_name

user_cards:
  id
  user_id
  card_id

A card has a set
A set has many cards
A card has many user_cards
A user_card has a user
A user_card has a card

Now, say I want to have a page that lists out all the cards a user has.
Right now I have one user, so I'm not doing much on the user id.  Ok, that's
simple, I just do:

my $user_cards =3D $c->model('Model::for::UserCards');
my $cards =3D $user_cards->search_related('cards');

Sweet, now I'm getting a list of all cards that my single user has right
now.  Now I want to be able to add to the results what set that card is
from, and here is where I get hung up.  I can't figure out the syntax to add
to the my $cards to get it to join on the sets table.  Is there some
documentation somewhere that I'm missing?  I've looked at
DBIx::Class::Manual::Cookbook for the join/multi join examples, and they
seem to be what I want to do, but I can't quite translate the example to my
situation.  If I should have sent this to a DBIx list, I apologize, since
this seems to straddle the two realms.  None of the Catalyst docs regarding
DBIx seem to be much help in this respect.

Thanks for your time,
Leanan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20080928/3da44=
56f/attachment.htm


More information about the Catalyst mailing list