[Dbix-class] Filtering with Many-to-Many relationship

Oleg Kostyuk cub.uanic at gmail.com
Tue Sep 22 10:23:48 GMT 2009


I think, you just need to join twice with tags table, and this will
give you what you want:

my $product_rs = $schema->resultset('Product')->search_rs(
  { # conditions will be AND'ed by default
   'product_tags.tag_id' => 'tagA',
   'product_tags_2.tag_id' => 'tagB',
  }, {
   join => [ 'product_tags', 'product_tags' ],
  }
);

For manuals, see here:
http://search.cpan.org/~ribasushi/DBIx-Class-0.08112/lib/DBIx/Class/Manual/Joining.pod#Joining_to_the_same_table_twice

PS: I will not be surprised, if this variant will be faster than all other ;)

-- 
Sincerely yours,
Oleg Kostyuk (CUB-UANIC)



More information about the DBIx-Class mailing list