[Dbix-class] for update + foreign key
Rob Kinyon
rob.kinyon at gmail.com
Tue Dec 22 15:50:02 GMT 2009
On Tue, Dec 22, 2009 at 10:37, Roman Tarakanov <romantarakanov at gmail.com> wrote:
> Then I'm trying to use DBIX (through catalyst) in the following way:
DBIC, not DBIX. DBIX is a namespace. DBIC is a project.
> sub new {
> ....
> my $res =
> $db_conn->resultset('a')->search({id=>$id},{for=>'update'})->single;
> $self->{_data} = $res;
> ...
> }
You're storing the row in $self->{_data}, not the resultset. There's
no way to get from the row back to the resultset that generated it,
nor does that really make sense to be able to do.
> 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=? FOR UPDATE;
> SELECT * FROM b WHERE id=?;
>
> 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?
One solution could be:
sub b {
...
return \%{ $db_conn->resultset('b')->search({id=>$self->{_data}->b_id},{for=>'update'})->single->getcolumns
};
}
Rob
More information about the DBIx-Class
mailing list