[Dbix-class] $rs->count and auto increment columns
Will Hawes
info at whawes.co.uk
Wed Aug 2 18:40:18 CEST 2006
Using DBIC 0.07, I have some code that does something along the lines of
the following:
package My::Schema::User;
__PACKAGE__->add_columns(qw/ id name tel /);
__PACKAGE__->set_primary_key('id'); # 'id' is an auto incrementing column
# elsewhere...
# get an empty resultset
$rs = $schema->resultset('User')->search( { id => undef } );
$rs->count; # runs something like "SELECT ... FROM user WHERE me.id IS
NULL" and returns 0
# insert a new record in "user" table ( "id" column is auto populated )
$row = $rs->update_or_create( { name => 'name', tel => '11' }, { key =>
'primary' } );
$rs->count; # runs same query as before so still returns 0
Probably a silly question, but it's late in the afternoon and my brain's
tired. I want to keep hold of a resultset containing the newly created
record for use elsewhere in my application, i.e. in the above case I'd
like $rs->count to return 1 and $rs->first to return the new record. Is
there a way to get the resultset to auto-update its query as new records
are added? Or do I need to create a new resultset to be able to do this?
More information about the Dbix-class
mailing list