suaveant has asked for the wisdom of the Perl Monks concerning the following question:
Basically the Catalyst helper already set up the basics of my tables, and now I am trying to figure out how to make queries and what else I need to do to hook things together. I got a basic search on a table working using search_like(caption => '%test%'); and I got a join to work by setting up a has_many relationship, but only one way.
Database structure
I am making an image gallery system, the tables I am currently interested in is a list of images, a list of galleries and a map of image ids (iid) to gallery ids (gid) to specify which image is in which galleries. So my 'iid' maps from the 'images' table to the 'gallery_map' table one or more times, which has only 'iid' and 'gid'. The 'gallery_map' table gives the 'gid' which maps me to the 'galleries' table, which stores a name and description of the gallery.
so images 1-* gallery_map 1-1 galleries
Qusetions
now... question one, what kind of relationships should I set up to allow any kind of querying back and forth between these... just a has_many from images to gallery_map and a has_one from gallery_map to galleries or are there others I should include as well.
question two, I was able to search for a gid in gallery_map and get back the images it contained using:
but when I tried to search for an iid in images joined with gallery_map to get the galleries an image is in I got lost... it seems to want the relationship descriptor to specify the table a field is from since Images and images both gave errors... what am I doing wrong there?# relationship in Images is __PACKAGE__->has_many(GalleryMaps => 'Gall +ery::Model::DBIC::GalleryMap', 'iid'); my @list = Gallery::Model::DBIC::Images->search_like({ 'GalleryMaps.gi +d' => 22 },{ join => qw( GalleryMaps )});
I realize I may just be going about this all wrong, I'm used to just building the queries myself, I am probably making this more difficult than it is. I appreciate any help, maybe I won't have to bang my head against this stuff for 2 days to work it out.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Help with joins in DBIx::Class
by castaway (Parson) on Feb 02, 2006 at 17:35 UTC | |
by suaveant (Parson) on Feb 02, 2006 at 20:31 UTC |