Skip Menu |
 
rt.cpan.org will be shut down on March 1st, 2021.

This queue is for tickets about the HTML-FormFu-Model-DBIC CPAN distribution.

Report information
The Basics
Id: 46094
Status: open
Priority: 0/
Queue: HTML-FormFu-Model-DBIC

People
Owner: Nobody in particular
Requestors: dluke [...] geeklair.net
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.04003
Fixed in: (no value)



Subject: Invalid error message: "The primary key and the foreign key may not be the same column in class"
When attempting to update a table (foo) that has a belongs_to relationship with another table (bar - which has an auto-generated has_many relationship back to foo), I get an error message: "The primary key and the foreign key may not be the same column in class MyDB::Bar" $info (from line 506 of HTML/FormFu/Model/DBIC.pm) is: $VAR1 = { 'cond' => { 'foreign.bar_id' => 'self.bar_id' }, 'source' => 'MyDB::Bar', 'attrs' => { 'is_foreign_key_constraint' => 1, 'undef_on_null_fk' => 1, 'accessor' => 'filter' }, 'class' => 'MyDB::Bar' }; The relationships which are generated by DBIx::Class::Schema::Loader looks like this: in MyDB::Bar - __PACKAGE__->has_many( "foos", "MyDB::Foo", { "foreign.bar_id" => "self.bar_id" }, ); in MyDB::Foo - __PACKAGE__->belongs_to( "bar_id", "MyDB::Bar", { bar_id => "bar_id" }, ); perl 5.10.0 on Darwin 9.7.0 (Mac OS X 10.5.7).
Download (untitled) / with headers
text/plain 506b
A workaround that works for me (so far), is to not have DBIx::Class::Schema::Loader generate the relationships. When adding them by hand to the generated class files, I've avoided using the field name as the relationship name, and this seems to fix the problem (or, passing in no_follow to the update is also an option for this particular form). The hand-created relationships look like: __PACKAGE__->has_many(items => 'MyDB::Foo', 'bar_id'); __PACKAGE__->belongs_to(my_bar => 'MyDB::Bar', 'bar_id');
Download (untitled) / with headers
text/plain 270b
All the condition examples in DBIx::Class::Relationship and DBIx::Class::ResultSource ->add_relationship() use { 'foreign.id' => 'self.id' } not { id => 'id' } So I'm not sure whether we're being too strict or whether DBIx::Class::Schema::Loader is being sloppy
Download (untitled) / with headers
text/plain 642b
On Thu May 21 05:38:40 2009, CFRANKS wrote: Show quoted text
> So I'm not sure whether we're being too strict or whether > DBIx::Class::Schema::Loader is being sloppy
At one point, I tried editing the generated class to use foreign.id and self.id, but still got the error message (it looks like foreign and self are removed from the keys before comparing them to test in line 501 of DBIC.pm). I also temporarily commented out the croak with the error message, but that did not work either. I think the problem may have been that DBIx::Class::Schema::Loader named the relationship with the same name as the id column and things got stuck looping forever.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.