Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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

by castaway (Parson)
on May 30, 2006 at 09:36 UTC ( [id://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

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.

    =cut
    --Brent Dax
    There is no sig.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2024-06-18 09:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.