[Dbix-class] for update + foreign key

Roman Tarakanov romantarakanov at gmail.com
Tue Dec 22 15:37:10 GMT 2009


Hello,

I'm having a bit of a problem and hope you can help me with this.
I have 2 tables, one with the foreign key to another (say):

CREATE TABLE a (
id INTEGER NOT NULL PRIMARY KEY,
data VARCHAR,
b_id INTEGER REFERENCES b(id)
);
CREATE TABLE b (
id INTEGER NOT NULL PRIMARY KEY,
data VARCHAR
);

Then I'm trying to use DBIX (through catalyst) in the following way:

sub new {
....
my $res =3D
$db_conn->resultset('a')->search({id=3D>$id},{for=3D>'update'})->single;
$self->{_data} =3D $res;
...
}

sub b {
...
return \%($self->{_data}->b->getcolumns);
}

However when this code is executed the following 2 queries are issued to the
DB:

SELECT * FROM a WHERE id=3D? FOR UPDATE;
SELECT * FROM b WHERE id=3D?;

note the absence of 'FOR UPDATE' in the second query.

My question is if there is a way to force 'FOR UPDATE' to the second query,
or have it "inherit" from the original query?

PS: I'm using postgresql with autocommit=3D>0 if that makes any difference.

Thanks in advance,
Roman
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20091222/eb2=
cb2f8/attachment.htm


More information about the DBIx-Class mailing list