Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: Help with joins in DBIx::Class

by castaway (Parson)
on Feb 02, 2006 at 17:35 UTC ( #527387=note: print w/replies, xml ) Need Help??

in reply to Help with joins in DBIx::Class


Depends on what you want to be able to see from what other thing.. Do you want to be able to list images from a gallery? Do you want to be able to get the galleries an image is in? All that is is the reverse of the previous relationship, i.e.:

# in Images: __PACKAGE__->has_many('GalleryMaps' => 'Gallery::Model::DBIC::Galler +yMap', 'iid'); # in GalleryMap: __PACKAGE__->belongs_to('iid' => 'Gallery::Model::DBIC::Images'); __PACKAGE__->belongs_to('gid' => 'Gallery::Model::DBIC::Galleries'); # in Galleries __PACKAGE__->has_many('GalleryMap' => 'Gallery::Model::DBIC::Gallery +Map', 'gid');
Now, using the latest release, which is 0.05, you can do:
# Get images in a gallery, assuming $g is a gallery: my @images = $g->GalleryMaps->search_related('iid'); # Get galleries an image is in, assuming $i is an image: my @galleries = $i->GalleryMaps->search_releated('gid');

.. All code untested, but thats how it works.. The actual joins between the tables will be done behind the scenes. Try setting DBIX_CLASS_STORAGE_DBI_DEBUG=1 in your shell environment, to see the SQL queries it creates.


Replies are listed 'Best First'.
Re^2: Help with joins in DBIx::Class
by suaveant (Parson) on Feb 02, 2006 at 20:31 UTC
    Ahh.. cool.. I wasn't sure about the whole belongs_to bit, thanks.

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://527387]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2020-06-01 17:30 GMT
Find Nodes?
    Voting Booth?
    Do you really want to know if there is extraterrestrial life?

    Results (5 votes). Check out past polls.