Hey all, I'm hoping someone can clarify for me an exception that get's thrown 
in Relationship::Base. I'm have multipurpose comments table that could be used 
for commenting on different kinds of objects in a schema.  Rather than having 
individual join-tables to cement the relationships, I want to using a compound 
foreign key of object_type + object_id.
Assume that I have:
  TABLE post (    'id' int(11) NOT NULL AUTO_INCREMENT,    'text' 
varchar(3000),    'created_at' datetime NOT NULL,    PRIMARY KEY ('id')  )
  TABLE comment (    'id' int(11) NOT NULL AUTO_INCREMENT,    'object_type' 
varchar(32) NOT NULL,    'object_id' int(11) NOT NULL,    'text' varchar(3000), 
   'created_at' datetime NOT NULL,    PRIMARY KEY ('id'),    KEY 'object' 
('object_type', 'object_id')  )
I have the Result class relationships built as follows using 
DBIx::Class::Relationship::Base's new-ish support for coderefs:
  __PACKAGE__->has_many(    comments => '::Comment',    sub {      my $args = 
shift;      return {        "$args->{foreign_alias}.object_id"   => { -ident => 
"$args->{self_alias}.id" },        "$args->{foreign_alias}.object_type" => 
'post',      };    }  );
But this throws the following exception:
  # DBIx::Class::Relationship::Base::new_related(): Custom relationship 
'comments' does not resolve to a join-free condition fragment at ...
Which comes from the new_related method:
    $self->throw_exception("Custom relationship '$rel' does not resolve to a 
join-free condition fragment")      if $crosstable;
If I comment that check out, I can use the above has_many without issue. So I'm 
curious:
  - What is that exception meant to overcome?  - Why must my relationship 
resolve to a "join-free" condition?
_______________________________________________
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/dbix-class@lists.scsys.co.uk

Reply via email to