Update: Added code to generate the params.

Hmm - that might be pretty hard (I assume that you want an article that is linked to all of the tags in @with instead of the castaway's interpretation). Here are some loose thoughts.

Lets take a bit simplified case where the @with contains the articlelinks ids and not think about the @without part at all. Than you need a query like:

SELECT * FROM article, articlelinks, articlelinks articlelinks_2, articlelinks artic +lelinks_3 ... WHERE article.id = articlelinks.article AND articlelinks.id = $with[0] AND article.id = articlelinks_1.article AND articlelinks_1.id = $with[1] A +ND ...
To produce this with DBIC you need something like:
my %params; $params{'articlelinks.id'} = $with[0]; for my $i ( 2 .. (scalar @with) - 1 ){ $params{"articlelinks_$i.id"} = $with[$i - 1]; } my @articles = $schema->resultset('articles')->search( \%params, { join => [ 'articlelinks' x scalar( @with ) ] } );
The @without part is a bit simpler, thanks to De Morgan lows. But how to compose those two parts? In raw SQL I would use 'EXCEPT' but in DBIC? And how to go from the list of 'articlelinks' ids to tags?

More questions than answers here - but I've heard mst was looking for hard cases so perhaps some day he shall simplify that? I'm interested - as I use a similar structure in my bookmarking app.


In reply to Re: DBIx::Class and many-to-many searching by zby
in thread DBIx::Class and many-to-many searching by BrentDax

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.