Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

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

Relationships:

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.

C.


Comment on Re: Help with joins in DBIx::Class
Select or Download Code
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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (11)
As of 2015-07-08 08:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (98 votes), past polls