Skip Menu |

This queue is for tickets about the DBIx-Class CPAN distribution.

Report information
The Basics
Id: 104909
Status: open
Priority: 0/
Queue: DBIx-Class

People
Owner: Nobody in particular
Requestors: kes-kes [...] yandex.ru
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: (no value)
Fixed in: (no value)



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});
From: kes-kes [...] yandex.ru
NOTICE that 'populate' has no this disadvantage
On Wed Jun 03 17:56:15 2015, kes-kes@yandex.ru wrote: Show quoted text
> The code: > > $DBIC->resultset( $mtable )->related_resultset( $dtable )-
> >update_or_create( $row, { key =>'primary' } );
> > ... > > Because of create_or_update do not fill columns by values from master > table(related) from 'has_many' condition columns
You need to explain more of this issue. The code example above can not possibly work - how would one know from *which* $mtable row should we take the "server_id" from? If you had written: ...->resultset( $mtable ) ->search({ 'me.id' => $something }) ->related_resultset( $dtable ) -> >update_or_create( $row, { key =>'primary' } ) Then $something would be filled in correctly. You also mention that "populate doesn't have this problem" - in what regard? Please explain this further, ideally with a DBICTest-based test case demonstrating the problem (note - somebody will have to write this test anyway, it is a mandatory prerequisite for things getting fixed).
From: kes-kes [...] yandex.ru
close this bug report as error Show quoted text
>$DBIC->resultset( $mtable )->related_resultset( $dtable )->update_or_create( $row, { key =>'primary' } )
in this construction I must make some row active in $mtable So it must be rewrited as: Show quoted text
>$DBIC->resultset( $mtable )->find( $id )->related_resultset( $dtable )->update_or_create( $row, { key =>'primary' } )
and everything works fine
On Wed Jul 08 20:51:45 2015, kes-kes@yandex.ru wrote: Show quoted text
> > So it must be rewrited as:
> > $DBIC->resultset( $mtable )->find( $id )->related_resultset( $dtable > > )->update_or_create( $row, { key =>'primary' } )
> >
Note that this will issue 3 queries (select on mtable, select on on dtable, then update/insert on dtable) While the construct I suggested in https://rt.cpan.org/Ticket/Display.html?id=104909#txn-1503299 will *not* issue the first select on mtable at all - $id will properly inherit down the ->search_related chain. In any case - closing as requested :)
From: kes-kes [...] yandex.ru
You suggestion rise another problem $DBIC->resultset( $mtable )->search( { 'me.id' => $self->{__data}{id} } )->related_resultset( $dtable ) ->update_or_create( $row, { key => 'primary' } ); Works fine, but I can not change that by 'update_or_create_related': Can't locate object method "update_or_create_related" via package "SafeVPN::DB::ResultSet" at /home/feelsafe/public_html/www/autohandler line 603. $DBIC->resultset( $mtable )->search( { 'me.id' => $self->{__data}{id} } )->update_or_create_related( $dtable, $row, { key => 'primary' } );
Subject: Re: [rt.cpan.org #104909] Can not update_or_create for related_resultset
Date: Wed, 08 Jul 2015 21:21:40 +0200
To: bug-DBIx-Class [...] rt.cpan.org
From: Peter Rabbitson <ribasushi [...] cpan.org>
On 07/08/2015 09:18 PM, Eugen Konkov via RT wrote: Show quoted text
> Queue: DBIx-Class > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=104909 > > > You suggestion rise another problem > > $DBIC->resultset( $mtable )->search( { 'me.id' => $self->{__data}{id} } )->related_resultset( $dtable ) ->update_or_create( $row, { key => 'primary' } ); > > Works fine, but I can not change that by 'update_or_create_related': > > Can't locate object method "update_or_create_related" via package "SafeVPN::DB::ResultSet" at /home/feelsafe/public_html/www/autohandler line 603. > > > $DBIC->resultset( $mtable )->search( { 'me.id' => $self->{__data}{id} } )->update_or_create_related( $dtable, $row, { key => 'primary' } );
Right... because X_related are Result-only methods, they do not exist on ResultSet's (I know, inconsistent and silly, that's another remnant from the "wild west dev" days).
From: kes-kes [...] yandex.ru
This also cause error: $DBIC->resultset( $mtable )->search( { 'me.id' => $self->{__data}{id} } )->related_resultset( $dtable )->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 \"invoice_id\" violates not-null constraint\nDETAIL: Failing row contains (44372, null, null, asdf, df, 3, 34.00, 102.00). [for Statement \"INSERT INTO \"invoices_items\" ( \"count\", \"description\", \"total_price\", \"unit\", \"unit_price\") VALUES ( ?, ?, ?, ?, ? ) RETURNING \"id\"\" with ParamValues: 1='3', 2='asdf', 3='102', 4='df', 5='34'] at /home/feelsafe/public_html/www/autohandler line 599\n", }, "DBIx::Class::Exception") invoice_id does not filled in correctly. in case of 'find' all works fine PS. So, reopen it ))
Subject: Re: [rt.cpan.org #104909] Can not update_or_create for related_resultset
Date: Wed, 08 Jul 2015 21:26:28 +0200
To: bug-DBIx-Class [...] rt.cpan.org
From: Peter Rabbitson <ribasushi [...] cpan.org>
On 07/08/2015 09:23 PM, Eugen Konkov via RT wrote: Show quoted text
> Queue: DBIx-Class > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=104909 > > > This also cause error: > > $DBIC->resultset( $mtable )->search( { 'me.id' => $self->{__data}{id} } )->related_resultset( $dtable )->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 \"invoice_id\" violates not-null constraint\nDETAIL: Failing row contains (44372, null, null, asdf, df, 3, 34.00, 102.00). [for Statement \"INSERT INTO \"invoices_items\" ( \"count\", \"description\", \"total_price\", \"unit\", \"unit_price\") VALUES ( ?, ?, ?, ?, ? ) RETURNING \"id\"\" with ParamValues: 1='3', 2='asdf', 3='102', 4='df', 5='34'] at /home/feelsafe/public_html/www/autohandler line 599\n", > }, "DBIx::Class::Exception") > > > invoice_id does not filled in correctly. > >
That's... bizarre. Which version of DBIC is this?
From: kes-kes [...] yandex.ru
$VERSION = '0.082810';