[Dbix-class] how to implement Transactions (over different db tables) in a Catalyst project

J. Shirley jshirley at gmail.com
Mon Jul 6 04:12:20 GMT 2009


On Sun, Jul 5, 2009 at 7:43 PM, <kakimoto at tpg.com.au> wrote:

>
> hi , everyone,
>
>  i m trying to put transactions in place for my catalyst project.
>
>  For example, I would like to create a new user subscription.
>  What this does is,
>  - create two new Address objects (Address db table) where one's for
> billing address and another for main contact.
>  - create a new User Subscriptions object (and link the two new Address
> objects by IDs into attributes, billing_address_id and
> main_contact_address_id).
>
>
>  What I have refered to:
>
>
> http://search.cpan.org/~ribasushi/DBIx-Class-0.08107/lib/DBIx/Class/Manua=
l/Cookbook.pod<http://search.cpan.org/%7Eribasushi/DBIx-Class-0.08107/lib/D=
BIx/Class/Manual/Cookbook.pod>
>
> http://kobesearch.cpan.org/htdocs/DBIx-Class/DBIx/Class/Storage.html#txn_=
do
>
> http://kobesearch.cpan.org/htdocs/DBIx-Class/DBIx/Class/Storage.html#txn_=
begin
>
> http://kobesearch.cpan.org/htdocs/DBIx-Class/DBIx/Class/Storage.html#txn_=
commit
>
> http://search.cpan.org/~ribasushi/DBIx-Class-0.08107/lib/DBIx/Class/Stora=
ge.pm<http://search.cpan.org/%7Eribasushi/DBIx-Class-0.08107/lib/DBIx/Class=
/Storage.pm>
>
>
> In the past, when I had to work with just DBI, I would manually start a
> transaction and commit it at the end if no exceptions occur. In
>  the case of the latter, I will call a rollback.
>
>  How do I do it here in Catalyst/DbiX::Class land?
> I tried to read up the
> http://kobesearch.cpan.org/htdocs/DBIx-Class/DBIx/Class/Storage.html#txn_=
do
> doc but I can't see how the example can apply to Catalyst.
>
> It says, "$schema->txn_do($coderef)" to get the schema but in catalyst,
> we access the
> database tables directly. For example,
>
>
> my $rs =3D $c->model('myAppDB::UserSusbcriptions')->search( .. );
>
>
>
> I'm a bit confused and have looked in a few places. Can anyone please
> educate me?
>
> thank you:)
>
>
You're using Catalyst::Model::DBIC::Schema, so perhaps look at the pod
there?

http://search.cpan.org/~mstrout/Catalyst-Model-DBIC-Schema-0.25/lib/Catalys=
t/Model/DBIC/Schema.pm#schema
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20090705/5b7=
0e77c/attachment.htm


More information about the DBIx-Class mailing list