Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Catalyst: Users

transactions with DBIx::Class model

 

 

Catalyst users RSS feed   Index | Next | Previous | View Threaded


ansgar at 2008

Aug 2, 2008, 9:34 AM

Post #1 of 4 (756 views)
Permalink
transactions with DBIx::Class model

Hi,

I am using Catalyst with a DBIx::Class model (via C::M::DBIC::Schema)
and want to do serveral database updates in a transaction. To do this I
need the schema object to call $schema->txn_do($whatever).

The C::M::DBIC::Schema documentation says that I should be able to
access the schema object via $c->model("MyApp::Something")->schema, but
if I do so I get the following error:

Can't locate object method "schema" via package
"DBIx::Class::ResultSet"

I'm using
Catalyst 5.7014
Catalyst::Model::DBIC::Schema 0.20
DBIx::Class 0.08010

How can I use DBIx::Class' transaction support?

Regards,
Ansgar

--
PGP: 1024D/595FAD19 739E 2D09 0969 BEA9 9797 B055 DDB0 2FF7 595F AD19

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


plu at pqpq

Aug 2, 2008, 10:16 AM

Post #2 of 4 (705 views)
Permalink
Re: transactions with DBIx::Class model [In reply to]

Hi,

On 02.08.2008, at 18:34, Ansgar Burchardt wrote:

> The C::M::DBIC::Schema documentation says that I should be able to
> access the schema object via $c->model("MyApp::Something")->schema,
> but
> if I do so I get the following error:
>
> Can't locate object method "schema" via package
> "DBIx::Class::ResultSet"

let's say your model is called 'FilmDB' and you got an 'Actor' schema/
table. I guess you did something like $c->model('FilmDB::Actor')-
>schema->txn_do - right? Please try instead $c->model('FilmDB')-
>schema->txn_do(...).

# to access schema methods directly:
$c->model('FilmDB')->schema->source(...);

HTH,
plu

--
Johannes Plunien | mailto:plu [at] pqpq | http://www.pqpq.de
Attachments: smime.p7s (2.38 KB)


dbix-class at trout

Aug 2, 2008, 1:31 PM

Post #3 of 4 (694 views)
Permalink
Re: transactions with DBIx::Class model [In reply to]

On Sat, Aug 02, 2008 at 06:34:31PM +0200, Ansgar Burchardt wrote:
> Hi,
>
> I am using Catalyst with a DBIx::Class model (via C::M::DBIC::Schema)
> and want to do serveral database updates in a transaction. To do this I
> need the schema object to call $schema->txn_do($whatever).
>
> The C::M::DBIC::Schema documentation says that I should be able to
> access the schema object via $c->model("MyApp::Something")->schema, but
> if I do so I get the following error:
>
> Can't locate object method "schema" via package
> "DBIx::Class::ResultSet"

Assuming MyApp::Model::MyApp is your DBIC::Schema model

$c->model('MyApp')->schema;

is what you want.

$c->model('MyApp::Foo')

is just a shortcut for

$c->model('MyApp')->schema->resultset('Foo')

If you only have a $row or a $rw, then

$obj->result_source->schema

will get you back to the schema.

For more information, read the DBIx::Class::ResultSet, ::ResultSource,
::Schema and ::Row docs, plus the docs for Catalyst::Model::DBIC::Schema
itself.

Please also note that dbix-class has its own list so any more DBIC-specific
questions should go there.

--
Matt S Trout Need help with your Catalyst or DBIx::Class project?
Technical Director http://www.shadowcat.co.uk/catalyst/
Shadowcat Systems Ltd. Want a managed development or deployment platform?
http://chainsawblues.vox.com/ http://www.shadowcat.co.uk/servers/

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


ansgar at 2008

Aug 6, 2008, 4:11 PM

Post #4 of 4 (669 views)
Permalink
Re: transactions with DBIx::Class model [In reply to]

Hi,

Johannes Plunien <plu [at] pqpq> writes:

> On 02.08.2008, at 18:34, Ansgar Burchardt wrote:
>> The C::M::DBIC::Schema documentation says that I should be able to
>> access the schema object via $c->model("MyApp::Something")->schema,
>> but
>> if I do so I get the following error:
>>
>> Can't locate object method "schema" via package
>> "DBIx::Class::ResultSet"
>
> let's say your model is called 'FilmDB' and you got an 'Actor' schema/
> table. I guess you did something like $c->model('FilmDB::Actor')-
>> schema->txn_do - right? Please try instead $c->model('FilmDB')-
>>schema->txn_do(...).
>
> # to access schema methods directly:
> $c->model('FilmDB')->schema->source(...);

It works this way. I somehow missed the difference in the
documentation. Thanks for your help.

Regards,
Ansgar

--
PGP: 1024D/595FAD19 739E 2D09 0969 BEA9 9797 B055 DDB0 2FF7 595F AD19

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/

Catalyst users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.