Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: DBIx::Class and many-to-many searching

by castaway (Parson)
on May 30, 2006 at 09:36 UTC ( #552439=note: print w/replies, xml ) Need Help??

in reply to DBIx::Class and many-to-many searching

Hi, If you already have an array of tag row objects, then you want to do something like this:
@with = map { $_->id } @with; @without = map { $_->id } @without; my @articles = $schema->resultset('articles')->search({}, { join => { 'articlelinks' => 'tag' }, tag.tag => { '-not_in' => \@without, '-in' => \@with } });
This is basically an SQL::Abstract construct, look there for details.



Update: Fixed code.. maybe

PS: This will return all articles with any of the tags in @with, there's a discussion going on in #dbix-class as to whether you wanted any, or all of them..

Please give an example of the SQL you'd like to produce, for further help

Replies are listed 'Best First'.
Re^2: DBIx::Class and many-to-many searching (bare non-words)
by tye (Sage) on May 30, 2006 at 17:22 UTC

    tag.tag is likely not what you want:

    $_= $_->id() for @with, @without; my @articles= $schema->r­esultset('­articles')­->search( {­}, { join => { 'articleli­nks' => 'tag' }, 'tag.tag' => { '-not_in' => \@without, '-in' => \@with }, }, );

    - tye        

Re^2: DBIx::Class and many-to-many searching
by BrentDax (Hermit) on May 30, 2006 at 18:57 UTC

    For the record, I'm looking for articles with all of the tags in @with and none of the tags in @without.

    --Brent Dax
    There is no sig.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://552439]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2016-10-22 21:40 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (298 votes). Check out past polls.