Skip Menu |

This queue is for tickets about the DBIx-Class CPAN distribution.

Report information
The Basics
Id: 40701
Status: stalled
Priority: 0/
Queue: DBIx-Class

People
Owner: Nobody in particular
Requestors: bruce [...] fortressofgeekdom.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 0.08010
Fixed in: (no value)



Subject: delete_related doesn't allow object like create_related does
I came across this while using a linker table and attempting to use create_related and delete_related. When using delete_related, passing an object as the value of the relation does not work. The object is stringified instead of getting its primary key. I have attached a test that demonstrates the failure. I originally found this while using oracle, but it repeats just as well with sqlite. Just in case it matters, I found this on perl v5.8.8 built for i386-linux-thread-multi (CentOS). I've also reproduced on Ubuntu 8.10 (64bit).
Subject: related.t
use Test::More tests=>7; BEGIN { use_ok('Related') } unlink('links.db'); $db = Related->connect("dbi:SQLite:links.db"); isa_ok($db, 'Related'); $db->storage->dbh->do('create table a ( a_id integer primary key )'); $db->storage->dbh->do('create table b ( b_id integer primary key )'); $db->storage->dbh->do('create table ab ( a_id integer, b_id integer )'); my $a = $db->resultset('A')->create({'a_id'=>1}); isa_ok($a, 'Related::A'); my $b = $db->resultset('B')->create({'b_id'=>1}); isa_ok($b, 'Related::B'); $link = $a->create_related('links', { 'b_id' => $b } ); isa_ok($link, 'Related::AB'); is($db->resultset('AB')->count, 1); $link = $a->delete_related('links', { 'b_id' => $b } ); is($db->resultset('AB')->count, 0);
Subject: Related.pm
package Related::B; use base 'DBIx::Class'; __PACKAGE__->load_components("Core"); __PACKAGE__->table("b"); __PACKAGE__->add_columns( "b_id", { data_type => "integer", is_nullable => 0, size => undef } ); __PACKAGE__->set_primary_key("b_id"); package Related::A; use base 'DBIx::Class'; __PACKAGE__->load_components("Core"); __PACKAGE__->table("a"); __PACKAGE__->add_columns( "a_id", { data_type => "integer", is_nullable => 0, size => undef } ); __PACKAGE__->set_primary_key("a_id"); __PACKAGE__->has_many( "links", "Related::AB", { "foreign.a_id" => "self.a_id" } ); __PACKAGE__->many_to_many( "bs" => 'links', 'b_id' ); package Related::AB; use base 'DBIx::Class'; __PACKAGE__->load_components("Core"); __PACKAGE__->table("ab"); __PACKAGE__->add_columns( "a_id", { data_type => "integer", is_nullable => 0, size => undef } ); __PACKAGE__->add_columns( "b_id", { data_type => "integer", is_nullable => 0, size => undef } ); __PACKAGE__->set_primary_key("a_id", "b_id"); __PACKAGE__->belongs_to( "a_id" => "Related::A" ); __PACKAGE__->belongs_to( "b_id" => "Related::B" ); package Related; use base 'DBIx::Class::Schema'; __PACKAGE__->load_classes( qw/ A AB B / ); 1;
On Wed Nov 05 22:50:01 2008, bpa wrote: Show quoted text
> I came across this while using a linker table and attempting to use > create_related and delete_related. > > When using delete_related, passing an object as the value of the > relation does not work. The object is stringified instead of getting > its primary key. I have attached a test that demonstrates the failure.
This is a known issue, which can not be easily fixed in the current codebase. I committed a failing test based on your submission at [1], but it doesn't look like we will be able to fix this any time soon (not before the moose rewrite in 0.09). Stalling as the fix is pretty far away. [1] http://dev.catalyst.perl.org/svnweb/bast/revision/?rev=6426