Ciao, On Mon, Feb 2, 2015 at 8:32 PM, Maddy, Noel <nmad...@hfhs.org> wrote: > Luca, > > IIRC, if you pass any value (even NULL) for the pk column, then it bypasses > the sequence. > > You'll need to drop the pk column completely when $pk is undefined. > > I'd just use PerlX::Maybe, like this: > > my $current_ticket = $c->model('DB::Ticket')->find_or_new( maybe pk => $pk );
correct! In my case I use a less elegant technique building the hash ref to find_or_new before invoking it, so that I can add the pk or not: $params_ref = {}; $params_ref->{pk} = $pk if ( $pk ); my $current_ticket = $c->model('DB::Ticket')->find_or_new( $params_ref ); Another approach could have been to call separately find or new with a couple of conditionals: my $model = $c->model('DB::Ticket'); my $current_ticket = ( $pk ? $model->find ({pk => $pk}) : $model->new() ); Thanks, Luca _______________________________________________ List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class IRC: irc.perl.org#dbix-class SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/ Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk