[Catalyst] transactions with DBIx::Class model
Matt S Trout
dbix-class at trout.me.uk
Sat Aug 2 21:31:19 BST 2008
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/
More information about the Catalyst
mailing list