[Dbix-class] Defaulting a column by configuration

Bill Moseley moseley at hank.org
Fri Jun 1 21:42:06 GMT 2012

On Fri, Jun 1, 2012 at 3:09 PM, fREW Schmidt <frioux at gmail.com> wrote:

> Why not just add a database level default?  That would be easy, clean, and
> correct.  Plus if do that to remove the actual nulls from the DB

That only applies to new rows inserted.   These are old and existing
databases and trying to solve this outside of the database.

Really, all I'm asking is a good way to pass in a default outside of the
database.  My example with an extra key in connect_info seems to work.
Can you see that breaking anything in the future?

Same code works with more than one database and the default is different
for each database.   So the code need to either look at something like the
dsn to determine what database is connected (and lookup the default in a
hash) or use some other value as I showed passed in with connect_info.

And it's a bit more complex (always is), because (sadly) NULL time_zone
means two things.  It means either "my timezone is undefined because I use
my "parent's" time_zone, and if that isn't set then default to the config
value" or it means, well, it's not defined and therefore need to use an
appropriate default.

   return $self->parent ? $self->parent->time_zone : $default_time_zone;

Yes, a bit ugly.

-- =

Bill Moseley
moseley at hank.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20120601/d8c=

More information about the DBIx-Class mailing list