I have started playing with Catalyst and I am trying to do things "the right way" by using a database abstraction to make my life simpler. Of course... I have to shift my paradigm in order to do it ;) and I am looking for some help.

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:

# 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 )});
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?

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.

                - Ant
                - Some of my best work - (1 2 3)


In reply to Help with joins in DBIx::Class by suaveant

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.