[Dbix-class] Defaulting a column by configuration
fREW Schmidt
frioux at gmail.com
Fri Jun 1 20:09:06 GMT 2012
.
On Fri, Jun 1, 2012 at 9:14 AM, Bob MacCallum <uncoolbob at gmail.com> wrote:
> On Fri, Jun 1, 2012 at 2:43 PM, Bill Moseley <moseley at hank.org> wrote:
>
>> I have a time_zone column, but sadly it allows nulls. Fixing the
>> database would be the correct approach, but for now I'm looking at
>> defaulting the column. But, the default value depends on which database=
we
>> are connected to.
>>
>> The result class is used in both a Catalyst app and in cron jobs. Both
>> the Catalyst app and the cron jobs pull the connect_info from a single
>> config config, so the only thing I really have in common for all uses is
>> connect_info.
>>
>> So, in the result class I can use "around time_zone =3D> sub {}" to set =
the
>> default
>>
>> One option is to just do a match on the database name in the dsn:
>>
>> $self->result_source->storage->connect_info->[0]->{dsn}.
>>
>>
>> but I can't be sure someone won't change that later.
>>
>> Now I'm looking at just adding a "default_time_zone" to connect_info and
>> then inspecting:
>>
>> $self->result_source->storage->connect_info->[0]->{default_time_zone}.
>>
>> And then do:
>>
>> around time_zone =3D> sub {
>> my $orig =3D shift;
>> my $self =3D shift;
>> return $self->$orig( @_ )
>> || $self->result_source->storage->connect_info->[0]->{default_time_zone};
>> };
>>
>> Is there a more elegant solution to this?
>>
>> I don't like stuffing non-database args into connect_info, of course, but
>> it seems like the only thing I have available in all my environments.
>>
>
> couldn't/shouldn't the default timezone be stored in the db, in a simple
> key/value table called "meta" or similar?
>
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
-- =
fREW Schmidt
http://blog.afoolishmanifesto.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20120601/102=
92505/attachment.htm
More information about the DBIx-Class
mailing list