2011/2/8 Peter Rabbitson <[email protected]>:
> Skye Shaw wrote:
>> Is it possible to have DBIC populate a newly created instance with the
>> underlying table's defaults when a value isn't provided?
>
> The reason is that having every insert be followed by a select is...
> how shall I put it, insane?!

Insane implementations shouldn't disqualify very sane ideas.

An ORM should know the details of the tables and columns its mapping.
Particularly in cases where the user actually specifies this
information within the ORM's method calls:

__PACKAGE__->add_columns(
     active => {
       data_type => 'tinyint',
       default_value => 1
     }
)


> 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

Well, what I want is $db->resultset('Account')->create/new to respect
the underlying table's defaults.

If an account table has an attribute named active that defaults to 1,
I would expect that, when using an ORM, newly instantiated
-nevertheless persisted- instances of the Account class would default
to 1 too. Not the opposite. IMHO the current behavior is broken.

_______________________________________________
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