[Dbix-class] query for m:n relation

David Schmidt davewood at gmx.at
Sun Oct 3 15:59:33 GMT 2010


On Sun, Oct 3, 2010 at 4:59 PM, Charlie Garrison <garrison at zeta.org.au> wrote:
> Good morning,
>
> On 3/10/10 at 2:42 PM +0200, David Schmidt <davewood at gmx.at> wrote:
>
>>How to express this query for DBIx::Class is beyond my still evolving
>>DBIC skills.
>
> Without seeing some of your schema, real examples won't be possible. This might get you started.
>
> $pictures_rs->search(
>  {
>    'tags.id' => { -in => \@tag_ids }
>  },
>  {
>    join => { 'picture_tags' => 'tags' }
>  }
> );
>
>
> Charlie
>
> --
>   Ꮚ Charlie Garrison ♊ <garrison at zeta.org.au>
>
> O< ascii ribbon campaign - stop html mail - www.asciiribbon.org
> 〠  http://www.ietf.org/rfc/rfc1855.txt
>
> _______________________________________________
> 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/dbix-class@lists.scsys.co.uk
>


This did the trick. Thanks for your input.

        return $self->search(
            {
                tag_id => { -in => \@tag_ids },
            },
            {
                join        => 'picture_tags',
                group_by    => ['me.id', 'me.name'],
                having      => { 'count(tag_id)' => { '=', scalar @tag_ids } }
            }
        );



More information about the DBIx-Class mailing list