================================<br>WHAT I'M TRYING TO DO:<br>================================<br>I have three tables: photos, galleries, tags.<br>In Catalyst, I'm trying to retrieve photo info by <br>searching on photos, joined to their tags, and joined<br>to the galleries table that the photo's filesystem <br>location. <br>================================<br>MY APPROACH (I'm open to another, if there's a better way)<br>================================<br>I *think* I need to search on photos table, and join galleries<br>and tags; but I can't seem to get the syntax right, or <br>I've done some silly thing in my setup.<br><br>I've tried variations of this, to no avail:<br><br>my $photo_obj = $c->model('CatapultDB::Photos')->search(<br> { <br> 'tags.tag' => "$tag",
<br> },<br> { <br> join => [qw/ tags galleries /],<br> }<br> )->page($page);<br><br>================================<br>SCHEMA DETAILS:<br>================================<br>CREATE TABLE Photos (<br> id SERIAL NOT NULL PRIMARY KEY,<br> gallery INTEGER NOT NULL<br>
references Galleries(id)<br> ON DELETE CASCADE,<br> name VARCHAR(150) NOT NULL,<br> filename VARCHAR(150) NOT NULL,<br>);<br><br>In Photos class:<br>__PACKAGE__->belongs_to("gallery", <br>"Catapult::Schema::CatapultDB::Galleries", <br>{ id => "gallery" });<br>__PACKAGE__->has_many("tags", <br>"Catapult::Schema::CatapultDB::Tags", <br>{ "foreign.photo" => "self.id" });<br>================================<br>CREATE TABLE tags (<br> id SERIAL NOT NULL PRIMARY KEY,<br> photo INTEGER REFERENCES photos(id)<br> ON DELETE RESTRICT,<br>
tag VARCHAR(100) NOT NULL<br>);<br><br>In Tags class<br>__PACKAGE__->belongs_to("photos", <br>"Catapult::Schema::CatapultDB::Photos", <br>{ id => "photo" });<br>================================<br>CREATE TABLE Galleries (<br> id SERIAL NOT NULL PRIMARY KEY,<br> name VARCHAR (150) UNIQUE NOT NULL,<br> directory VARCHAR(50) UNIQUE NOT NULL,<br>);<br><br>In GAlleries class:<br>__PACKAGE__->has_many("photos", <br>"Catapult::Schema::CatapultDB::Photos", <br>{ "foreign.gallery" => "self.id" },<br>);<br><br>NOTE, I have found that this query works in psql:<br><br>SELECT *<br>FROM photos<br>JOIN galleries<br>ON photos.gallery = galleries.id<br>JOIN tags<br>ON photos.id = tags.photo<br>WHERE tags.tag =
'sunshine';<br><br>/dennis<br><br><br>