[Dbix-class] create without setting a nullable foreign key, then accessing relationship

Ash Berlin ash_cpan at firemirror.com
Wed Jun 11 12:53:34 BST 2008


On 11 Jun 2008, at 12:35, Adam Sjøgren wrote:

>  Hi.
>
> If I create a new row in the database, in a table that has an optional
> foreign key, which isn't filled in in the create-call, and then call  
> the
> belongs_to relationship accessor on the resulting object, I get an
> object back for the foreign key, when I use DBIx::Class 0.08008; I
> didn't in 0.08007.
>
> I am wondering whether this is expected behaviour?
>
> Abbreviated example:
>
>  # fleet_id not filled in when calling create:
>  my $car2=$schema->resultset('CarDB::Car')->create({
>                                                     id=>2,
>                                                     plate=>'BBB 202',
>                                                    });
>
>  my $fleet2=$car2->fleet; # Searches fleet table with no WHERE clause
>  print defined $fleet2 ? "Fleet returned, car2\n" : "No fleet  
> returned, car2\n";
>
> prints "Fleet returned, car2" (full example below).
>
> I have bisected my way to r3804 introducing this change, but I am not
> exactly sure what the correct cure is, if it is indeed wrong.
>
>
> This has been discussed on the mailinglist before, Damon Snyder asked
> about it in:
> <http://article.gmane.org/gmane.comp.lang.perl.modules.dbix-class/ 
> 5331>
> and mike provided a test-patch in:
> <http://article.gmane.org/gmane.comp.lang.perl.modules.dbix-class/ 
> 5443>.
> The test-patch broke some other patches, so I posted an updated patch
> that doesn't:
> <http://article.gmane.org/gmane.comp.lang.perl.modules.dbix-class/ 
> 5653>
> It probably went unnoticed because of the age of the thread.
>

Hmm, seems like a bug to me.

Do you think you could convert your test suite to use the existing  
tables in the DBICTest schema (you can add a table or some rels if  
needed)?

-ash


More information about the DBIx-Class mailing list