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> |
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