[Dbix-class] Re: Populating Instance With Column's Defaults

Skye Shaw skye.shaw at gmail.com
Wed Feb 9 19:41:14 GMT 2011


2011/2/9 Peter Rabbitson <rabbit+dbic at rabbit.us>:
> Dagfinn Ilmari Mannsåker wrote:
>> Peter Rabbitson <rabbit+dbic at rabbit.us> writes:
>>> 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?
>>>
>>> The reason is that having every insert be followed by a select is...
>>> how shall I put it, insane?!
>>
>> We already use INSERT ... RETURNING ... to get the ID if the DB supports
>> it, couldn't that be extended to get all the columns that weren't
>> specified in the ->new/->create call?
>
> Right, and this will introduce an insane amount of broken code, since your
> dev will work fine on a Pg version that supports IR, and will all of a
> sudden stop working entirely in production on a different db or on an
> older version of Pg, since now all the data you expected to be there is
> suddenly UNDEF.


I do not know DBIx internals but, on the surface, DBI does provide the
column_info method. Sure underlying driver support for this method can
vary but are there really any DBs that DBIx currently supports that
don't provide a way to query table metadata?

Loading the metadata once, when the class is loaded, is all that's needed.



More information about the DBIx-Class mailing list