Look at this: http://search.cpan.org/search?query=DBIx::Class::ResultSource::View
Take care possible performance issue. I'm afraid it is impossible to implement conditional join using "?" in DBIx::Class. On Tue, Apr 5, 2011 at 12:40 PM, Brian E. Lozier <[email protected]> wrote: > I've recently begun a small project and decided to try DBIx::Class. I > am trying to use prefetch to bring in some related data but one of the > joins should have an extra conditional on it. Here is the search: > > my $topics_rs = $schema->resultset('Topic')->search( > { forum_id => $forum_id }, > { > prefetch => 'topic_view' > }, > ); > > > The Topic.pm has a relationship: > > __PACKAGE__->might_have(topic_view => > 'Fan::DB::Schema::Result::TopicView', 'topic_id'); > > And TopicView.pm has relationships: > > __PACKAGE__->belongs_to(post => 'Fan::DB::Schema::Result::Post', > 'post_id'); > __PACKAGE__->belongs_to(myuser => 'Fan::DB::Schema::Result::User', > 'user_id'); > > I'm trying to have the LEFT JOIN "on" condition include the user_id, > so it gets something like this: > > SELECT * FROM topics LEFT JOIN topic_views ON (topics.topic_id = > topic_views.topic_id AND topic_views.user_id = ?) > > The idea is that I'll always get the "topics" information and only get > the "topic_views" information if topic_id matches and user_id matches > whatever I pass in. > > Is there a way to run a search query like this? > > Thanks, > Brian > > _______________________________________________ > List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class > IRC: irc.perl.org#dbix-class > SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/ > Searchable Archive: http://www.grokbase.com/group/[email protected] > -- Sincerely, Hu Hailin _______________________________________________ List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class IRC: irc.perl.org#dbix-class SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/ Searchable Archive: http://www.grokbase.com/group/[email protected]
