[Dbix-class] query for m:n relation

David Schmidt davewood at gmx.at
Sun Oct 3 12:42:45 GMT 2010


I have a m:n relation

picture --<>-- picture_tags --<>-- tags

my @tag_ids = qw/2 5 6/;

Return all pictures which have all tags of the input list set.

select *
from pictures p
where 3 = (
    select count(distinct t.id)
    from picture_tags pt
    inner join tags t on t.id = pt.tag_id
    where t.id in (2,5,6)
    and pt.picture_id = p.id
)

How to express this query for DBIx::Class is beyond my still evolving
DBIC skills.

david



More information about the DBIx-Class mailing list