[Dbix-class] BUG? Unable to resolve relationship

Ovid publiustemp-dbic at yahoo.com
Sat Dec 12 11:10:05 GMT 2009


----- Original Message ----

> From: Peter Rabbitson <rabbit+dbic at rabbit.us>
> > 
> > When I upgrade to 0.08115:
> > 
> >   My::Schema::Customer::account(): Unable to resolve relationship from 
> Customer to account: column account.account_id not loaded from storage (or not 
> passed to new() prior to insert()). Maybe you forgot to call ->discard_changes 
> to get defaults from the db. at loader.pl line 7
> 
> This is correct and expected. Read the error message more carefully. To break it 
> down:
> 
> *) You create a row, without specifying a value for account_id.
> *) The resulting object has only a name, and its autoinc id, dbic does not 
> assume
> that the value of account_id is NULL/undef, it simply isn't there (i.e. the 
> db-side
> default may be 0, or 42 or 'kinky sex')
> *) Since there is no value for the FK, the relationship can not be resolved and
> subsequently the exception you see is thrown.
> *) If you do what has been suggeste d- call discard_changes to make a db-trip to
> retrieve the missing values - everything will just work. Alternatively you can
> create() the row explici5tly specifying account_id => undef - this will work as
> expected too.

Hi Peter,

Thanks for your explanation.  That helps quite a bit.  I have a couple of comments.

1.  I've just created the object.  Having to call "discard changes" on something with no changes seems very counter-intuitive to me.  If I view the creation as the change, then "discard changes" implies that the creation will be discarded, but that's obviously not the case.  I'm still not sure I understand what's happening here.
2.  We have a very large performance-sensitive system.  Having to make a second trip to the database isn't ideal for us.
3.  Since the "account_id" has "is_nullable" set to a true value, would it be appropriate for DBIx::Class to assume that a missing nullable value is actually NULL and thus not throw an exception here?


Cheers,
Ovid
--
Buy the book         - http://www.oreilly.com/catalog/perlhks/
Tech blog            - http://use.perl.org/~Ovid/journal/
Twitter              - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6




More information about the DBIx-Class mailing list