[Catalyst] Two ways to create record
Matt S Trout
dbix-class at trout.me.uk
Sun Jan 13 18:24:42 GMT 2008
On Sun, Jan 13, 2008 at 04:47:38PM +0300, Alex Povolotsky wrote:
> Hello!
>
> In Tutorial (BTW, "CRUD" section of tutorial lacks U completely), I've
> seen this way of filling in the record:
>
> my $book = $c->model('GalleryDB::Gallery')->new({});
> $book->populate_from_widget($result);
which sets a bunch of data and then calls $book->insert_or_update;
> In InstantCRUD data is filled in with
>
> my $item = $result->save_to_db();
I have no idea how this works.
> Can anyone experienced tell me about drawbacks of both ways to do create?
Neither of these are standard DBIx::Class methods; the standard approach
is to do
my $obj = $rs->new(\%data);
<maybe use $obj->column_name($value) to set more data>
$obj->insert;
DBIx::Class::ResultSet provides a $rs->create(\%data) shortcut that calls
$obj->insert for you before returning it, but that really is just a
shortcut - the end effect is identical.
For more info, have a look at the DBIx::Class documentation on CPAN and
note that DBIC-specific questions can be asked on the dedicated dbix-class
list.
--
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