[Dbix-class] Re: Blessed objects as scalar values: what to do ?
BUCHMULLER Norbert
norbi.lists at nix.hu
Tue Nov 11 22:30:39 GMT 2008
Just to summarize the decisions:
On Thu, 6 Nov 2008 17:26:51 +0100 BUCHMULLER Norbert <norbi.lists at nix.hu>
wrote:
> > Therefore my proposal was to say : OK, let's treat objects like
> > scalars, but only if they have a method to effectively transform
> > themselves into a scalar. This makes it likely that such objects can
> > indeed be inserted into databases.
As discussed on IRC with mst, we should pass them intact, like current
CPAN SQLA does. I changed SQLA to reflect this.
> > I don't know, maybe this view is too strong ... but on the other hand,
> > do you have any real-world use cases where object references are
> > passed to DBI ?
>
> Well, maybe a bit contrived, but there may be cases when the default
> date format ('2008-11-06T16:14:45') that DateTime produces on
> stringification is not suitable for the db engine,
mst told that eg. InflateColumn::DateTime does this.
> > If we really want more flexibility, maybe what could be done is to add
> > a new option in the SQLA contructor SQL::Abstract->new(value_classes
> > => [qw/Foo::Bar, etc/]) In that scenario, object references would be
> > accepted as scalar values if and only if they belong to one of the
> > given classes (or descendants).
>
> I like it. (In the list we may accept strings - to use with isa()
> - and regexes - to use with ref() - , I suppose.)
There's still room for this improvement. (I just changed the behaviour
to pass objects intact and added a test case for an object that has no
stringification overload. I wanted to show you the patch first, but I
wasn't quick enough. Feel free to change it.)
norbi
More information about the DBIx-Class
mailing list