On 12/2/2006, "Matt Hilliard" <[EMAIL PROTECTED]> wrote: >I believe I've come across a bug in BRICAS/DBIx-Class-0.07003.tar.gz, >the synopsis is this: >I'm running from a Catalyst context, I start with a DBIx::Class with 2 >separate foreign keys to the same foreign table, both initially "NULL", >for example: > >package DB::Schema::Model; > >use strict; >use warnings; > >use base 'DBIx::Class'; > >__PACKAGE__->load_components("PK::Auto", "Core"); >__PACKAGE__->table("some_table_or_other"); >__PACKAGE__->add_columns( > "id", > { data_type => "INT", default_value => undef, is_nullable => 0, size >=> 11 }, > "assorted_other_data", > { data_type => "INT", default_value => 0, is_nullable => 0, size => >11 }, > "curr_address", > { data_type => "INT", default_value => undef, is_nullable => 1, size >=> 11 }, > "prev_address", > { data_type => "INT", default_value => undef, is_nullable => 1, size >=> 11 }, >); >__PACKAGE__->set_primary_key("id"); > >__PACKAGE__->might_have("curr_address", "Addresses", { "foreign.id" => >"self.curr_address" }); >__PACKAGE__->might_have("prev_address", "Addresses", { "foreign.id" => >"self.prev_address" }); >1; > >and I then call find_or_new_related() separately for each relationship, >with some processing, quite likely on different Catalyst action calls >for example: >my $curr = $model->find_or_new_related('curr_address', {}); ># do some processing, ># insert or update new values for $curr here and then persist >$curr->insert_or_update; > ># if $curr is new (which it is in this example) it will have a new id ># shove it back into $model >$model->update_from_related( 'curr_address', $curr ); > >The bug manifests itself in this way: >when I call >my $prev = $model->prev_address > >I get undef for $prev (which I should) however, if I call >$prev = $model->find_or_new_related('prev_address', {}); > >I get the $curr entry for $prev, (which I should not). > >This really looks like a bug to me, but if its something more like a >configuration issue, can I please get some insight?
You asked it to _find_ you the related row. Does address have a user ID in it? But anway, you've just asked it to find any row. But anyway, try the following $model->find_or_new_related('prev_address', { id => $model->get_column('prev_address') } ); Ash _______________________________________________ List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class Wiki: http://dbix-class.shadowcatsystems.co.uk/ IRC: irc.perl.org#dbix-class SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/ Searchable Archive: http://www.mail-archive.com/dbix-class@lists.rawmode.org/