Subject: | Can not update_or_create for related_resultset |
The code:
$DBIC->resultset( $mtable )->related_resultset( $dtable )->update_or_create( $row, { key =>'primary' } );
Cause next error:
bless({
msg => "DBIx::Class::Storage::DBI::_dbh_execute(): DBI Exception (unhandled by DBIC, ::Schema GCed): DBD::Pg::st execute failed: ERROR: null value in column \"server_id\" violates not-null constraint\nDETAIL: Failing row contains (44271, null, 5, 2, 3.3.3.3). [for Statement \"INSERT INTO \"listeners\" ( \"ip\", \"number\", \"type\") VALUES ( ?, ?, ? ) RETURNING \"id\"\" with ParamValues: 1='3.3.3.3', 2='2', 3='5'] at /www/autohandler line 495\n",
}, "DBIx::Class::Exception")
Because of create_or_update do not fill columns by values from master table(related) from 'has_many' condition columns
EXPECTED: related_resultset( $dtable )->server_id will be filled by resultset( $mtable )->id because of:
__PACKAGE__->table( $mtable );
__PACKAGE__->has_many( $dtable, 'DTable', 'server_id', {cascade_delete => 0});