On Tue, 25 Mar 2008, Alex Peters wrote:

Hi,

I'm struggling to convey a many-to-many relationship on the
same table with DBIx::Class.  I've read over all of the
relevant documentation on CPAN and I've read past posts to this
list that seemed closely relevant by subject[1].

I have a database table called CriterionConflict with two
columns, criterionA and criterionB.  This table intends to
document instances of Criterion records that cannot coexist.
The conflicts are bidirectional; there is no meaning to the
ordering of a pair of IDs in a CriterionConflict record.

I think a 'conflicts' accessor/mutator method in the Criterion
ResultSource class would be ideal, but I don't know how I might
go about this.  For the accessor side of things I imagine I'd
need to construct a ResultSet searching across both columns;
for the mutator I'd probably start out with something similar.

To get all conflicts for a criteria, regardless of order, you can add a relationship something like:

__PACKAGE__->has_many('conflicts', 'Schema::CriterionConflict',
                      [ { 'foreign.criterionA' => 'self.id' },
                        { 'foreign.criterionB' => 'self.id'} ]);


Which is a condition with an OR clause.

I'm also unsure as to whether I need a CriterionConflict
ResultSet class, since I can't see any value to making this
instantiable.

You never need one unless you have extra methods for the resultset.
Or did you mean a result class? You cant not have one of those ;)


_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/[EMAIL PROTECTED]

Reply via email to