Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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.

(Untested!)

C.

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


Comment on Re: DBIx::Class and many-to-many searching
Download Code
Re^2: DBIx::Class and many-to-many searching (bare non-words)
by tye (Cardinal) 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.

    =cut
    --Brent Dax
    There is no sig.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2014-07-14 10:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (257 votes), past polls