Re: [Catalyst] Two ways to create record

2008-01-16 Thread Matt S Trout
On Tue, Jan 15, 2008 at 04:38:36PM +0300, Alex Povolotsky wrote:
> Matt S Trout wrote:
> >
> >Neither of these are standard DBIx::Class methods; the standard approach
> >is to do
> >
> >my $obj = $rs->new(\%data);
> >
> >column_name($value) to set more data>
> >
> >$obj->insert;
> >  
> 
> ... I see. It does not depend on model implementation.
> 
> Ok than, assume I'm using DBI connection without AutoCommit (AutoCommit 
> is often a very bad practice).

Don't do that. Turn AutoCommit on and use DBIC's txn_do method.

If you leave AutoCommit off DBIC can't manage transaction depth properly
and you have to handle everything manually- which is *always* a very bad
practive.

Also, once again there's a dbix-class list and this discussion would be
more appropriate there.

-- 
  Matt S Trout   Need help with your Catalyst or DBIx::Class project?
   Technical Directorhttp://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@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Two ways to create record

2008-01-15 Thread Alex Povolotsky

Matt S Trout wrote:


Neither of these are standard DBIx::Class methods; the standard approach
is to do

my $obj = $rs->new(\%data);

column_name($value) to set more data>

$obj->insert;
  


... I see. It does not depend on model implementation.

Ok than, assume I'm using DBI connection without AutoCommit (AutoCommit 
is often a very bad practice). Where should I put commit/rollback calls?


Alex.


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


Re: [Catalyst] Two ways to create record

2008-01-13 Thread Alex Povolotsky

Matt S Trout wrote:

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.
  

It seems to obtain $result with

my $result = $w->action( $c->uri_for('do_add') )->process( $c->request );

And $result is a HTML::Widget::Result::DBIC instance, so save_to_db is

"HTML::Widget::DBIC::Result method to save the data from widget to
the database"


Neither of these are standard DBIx::Class methods; the standard approach
is to do

my $obj = $rs->new(\%data);

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.

  

Thanks a lot. I'll go read it. There is such a lot of useful Perl modues...

Alex.


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


Re: [Catalyst] Two ways to create record

2008-01-13 Thread Matt S Trout
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);

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 Directorhttp://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@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


[Catalyst] Two ways to create record

2008-01-13 Thread Alex Povolotsky

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);

In InstantCRUD data is filled in with

my $item = $result->save_to_db();

Can anyone experienced tell me about drawbacks of both ways to do create?

Alex.
 


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