Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
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 chanting in the Monastery: (8)
As of 2015-07-05 09:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (61 votes), past polls