Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Help with joins in DBIx::Class

by castaway (Parson)
on Feb 02, 2006 at 17:35 UTC ( [id://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.

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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://527387]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-03-28 18:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found