Skye Shaw wrote:
Hello,

Is it possible to have DBIC populate a newly created instance with the
underlying table's defaults when a value isn't provided?

Given my code (active defaults to 1):

my $user = $db->resultset('Account')->create({
  first_name =>'A',
  last_name => 'User'
});

print $user->active; #undef warning
$user = $db->resultset('Account')->find($user->id);
print $user->active; #now it's populated with 1

And this thread:
http://stackoverflow.com/questions/2106504/perl-dbixclass-default-values-when-using-new

The answer appears to be no. If so, what's the reason for this behavior?


The reason is that having every insert be followed by a select is...
how shall I put it, insane?! What you want is the (admittedly misnamed)
http://search.cpan.org/~abraxxa/DBIx-Class-0.08127/lib/DBIx/Class/Row.pm#discard_changes_%28$attrs?%29

Note that frew would be very happy if you contribute an "auto-retrieve
defaults" component to DBIx::Class::Helpers

_______________________________________________
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/[email protected]

Reply via email to