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.:
Now, using the latest release, which is 0.05, you can do:# 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');
# 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 |
In Section
Seekers of Perl Wisdom