|laziness, impatience, and hubris|
DBIx::Class and many-to-many searchingby BrentDax (Hermit)
|on May 30, 2006 at 07:58 UTC||Need Help??|
BrentDax has asked for the
wisdom of the Perl Monks concerning the following question:
I'm writing a Catalyst app using DBIx::Class accessing MySQL for my model. Two of my tables have a many-to-many relationship, and I'm having trouble constructing the right query for the problem at hand.
Okay, so I have the classic many-to-many relationship: an articles table, a tags table, and a links table with article and tag IDs. I'm using DBIx::Class to access these tables, and I have the relationships set up the way you would expect:
Now, at one point in my code I have two arrays with rows from the tags table. I want to find the articles with all of the tag rows in @with and none of the tag rows in @without. The articles can have tags that aren't in either array. (Oh, and to complicate things further, I may want to exclude articles which don't have certain values in columns of the articles table itself, but I'll burn that bridge when I get to it.) How do I do this?
My searching turned up Many-to-many relationships in databases : SOLVED, but I'm not sure how to apply this to DBIx::Class, or if it's even the right approach for this module. Any help would be appreciated.