[Dbix-class] Relationship::Base join-free exception question
Marco Palma
marcoapalma at yahoo.com
Mon Jul 6 00:44:54 GMT 2015
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?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20150706/9f4066f1/attachment.htm>
More information about the DBIx-Class
mailing list