[html-formfu] HTML::FormFu::Model::DBIC
t\update\create_belongs_to.t problems
Peter Shangov
pshangov at yahoo.com
Tue Mar 1 13:33:31 GMT 2011
Follow-up to my previous message:
The problem is in line 426 in DBIC.pm (current version on github):
$dbic->discard_changes unless( $dbic->$rel );
DBIx::Class throws an exception on $dbic->$rel if the foreign key column for $rel is undefined, except where the foreign key column has the same name as $rel, in which case undef is returned (since DBIx::Class actually executes $dbic->$column). An easy solution is simply to use eval:
$dbic->discard_changes unless( eval { $dbic->$rel } );
Cheers,
--
Peter
--- On Mon, 28/2/11, Peter Shangov <pshangov at yahoo.com> wrote:
> From: Peter Shangov <pshangov at yahoo.com>
> Subject: [html-formfu] HTML::FormFu::Model::DBIC t\update\create_belongs_to.t problems
> To: html-formfu at lists.scsys.co.uk
> Date: Monday, 28 February, 2011, 18:31
> Hi all,
>
> I have been struggling with this for the past couple of
> hours:
>
> The schema definition in t\lib\MySchema\Band.pm uses a
> relationship name (‘manager’) identical to the name of
> the foreign key column through which it is defined, and
> which runs against the naming conventions in our databases:
>
> __PACKAGE__->add_columns(
> id => {
> data_type => "INTEGER", is_nullable => 0 },
> manager => { data_type =>
> "INTEGER", is_nullable => 1 },
> …
> );
> …
> __PACKAGE__->belongs_to( manager =>
> 'MySchema::Manager' );
>
> If I change ‘manager’ to ‘manager_id’:
>
> __PACKAGE__->add_columns(
> id => {
> data_type => "INTEGER", is_nullable => 0 },
> manager_id => { data_type =>
> "INTEGER", is_nullable => 1 },
> );
> …
> __PACKAGE__->belongs_to( manager =>
> 'MySchema::Manager', ‘manager_id’ );
>
> prove t\update\belongs_to_create.t fails with the following
> error:
>
> MySchema::Band::manager(): Unable to resolve relationship
> 'manager' from object MySchema::Band=HASH(0x189d124): column
> 'manager_id' not loaded from storage (or not passed to new()
> prior to insert()). You probably need to call
> ->discard_changes to get the server-side defaults from
> the database.
>
> Any ideas why this change causes such a difference?
>
> Using:
> DBIx::Class 0.08127
> HTML::FormFu 0.08002
> HTML::FormFu::Model::DBIC 0.08002
>
> Cheers,
>
> --
> Peter
>
>
> _______________________________________________
> HTML-FormFu mailing list
> HTML-FormFu at lists.scsys.co.uk
> http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu
>
More information about the HTML-FormFu
mailing list