Skip Menu |
 

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

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

People
Owner: Nobody in particular
Requestors: martin.renvoize [...] ptfs-europe.com
Cc:
AdminCc:

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



Subject: find_or_create accorss relationships bug?
Date: Fri, 13 Nov 2015 12:24:53 +0000
To: bug-DBIx-Class [...] rt.cpan.org
From: "Renvoize, Martin" <martin.renvoize [...] ptfs-europe.com>
Download (untitled) / with headers
text/plain 1.2k
So, I pasted the above into IRC this morning and castaway at least agreed he 'thinks' it's likely a bug.. so I thought I'd record it. I am intending to submit a pull request with at least a failing test case shortly. 1 So I'm attempting to populate a bridge table. 2 3 The three tables in question are: 4 5 Role, Privilege and RolePrivilege. 6 7 My code is: 8 9 $schema->resultset('RolePrivilege')->find_or_create({role => {name => 'admin'}, privilege => {name => 'config-update'}); 10 11 Looking at DBIC_TRACE this gets most of the way there.. 12 13 SELECT "me"."id", "me"."name" 14 FROM "roles" "me" 15 WHERE "me"."name" = 'admin'; 16 17 SELECT "me"."id", "me"."name", "me"."description" 18 FROM "privileges" "me" 19 WHERE "me"."name" = 'config_update'; 20 21 But the final insert doesn't do a 'find' before attempting the create, so I get constraint failures. 22 23 INSERT INTO "role_privileges"( "privilege", "role" ) 24 VALUES( '1', '20' ) 25 26 Am I expecting too much of the logic.. bug of feature? Martin Renvoize Software Engineer, PTFS Europe Ltd Content Management and Library Solutions Skype: Landline: 0203 286 8685 Mobile: 07725985636 http://www.ptfs-europe.com
On Fri Nov 13 13:25:34 2015, martin.renvoize@ptfs-europe.com wrote: Show quoted text
> 7 My code is: > 8 > 9 $schema->resultset('RolePrivilege')->find_or_create({role => > {name => 'admin'}, privilege => {name => 'config-update'}); > 10
There is something specific about your code that makes things fail - please get me the definitions of RolePrivelege and the related classes. The functionality you described works just fine: ~/devel/dbic$ perl -It/lib -Ilib -MDBICTest -e ' my $s = DBICTest->init_schema; $s->storage->debug(1); $s->resultset("CD_to_Producer")->find_or_create({ cd => { cdid => 2 }, producer => { producerid => 1 } }) ' producing SELECT me.cd, me.producer, me.attribute FROM cd_to_producer me WHERE ( ( me.cd = ? AND me.producer = ? ) ): '2', '1' SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track FROM cd me WHERE ( me.cdid = ? ): '2' SELECT me.producerid, me.name FROM producer me WHERE ( me.producerid = ? ): '1' INSERT INTO cd_to_producer ( cd, producer) VALUES ( ?, ? ): '2', '1'


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.