[CDBI] How do you get the raw db value of a column rather than inflated object

Peter Speltz peterspeltz at gmail.com
Mon Feb 13 15:37:00 GMT 2006


On 2/11/06, Bill Moseley <moseley at hank.org> wrote:
> On Sat, Feb 11, 2006 at 03:16:58PM -0600, Peter Speltz wrote:
> > On 2/11/06, Bill Moseley <moseley at hank.org> wrote:
> > > On Sat, Feb 11, 2006 at 06:57:32AM -0600, Peter Speltz wrote:
> > >
> > >   $object->my_column->id
> >
> >
> > Problem with that is you have to know you are dealing with an inflated
> > column and also a CDBI object in order to accurately get at the raw
> > value.   Has_a s can be inflated to any object.  I could call deflate
> > explicitly but it is not documented how to do that and  I cant remeber
> > if it is possible. I posted a while back asking. Need to search for
> > that thread.
>
> I'm curious.  Why do you need the raw column value in addition to the
> inflated value?
>

dont need it in addition.  I just need the raw value to edit. The
routine that  makes inputs for editting is setting  stringified
objects as the values for the input boxes rather than the actual  raw
column value. You can see how this is trouble when you want to edit a
datetime and end up with "Tues Nov. 3, 1998" in the input box.  Indeed
 I should have a better interface for editing date times yet but this
is just and example. It is a general problem.  The general solution i
found is just to use the deflate method or deflate the default class
dbi way. I wish
CDBI set a deflate method explicitly in metadata if you do not. That
would be nice.

if ($inflated_obj->can ($meta->{args}{deflate}) { # call it }

> I wonder if you could do something like this in your base class:
>
> <untested>
>
> sub _attribute_store {
>     my $self = shift;
>     my $vals   = @_ == 1 ? $_[0] : {@_};
>     for my $key ( keys %$vals ) {
>         next if ref $vals->{$key};
>         $self->{$key . '_raw'} = $vals->{$key};
>     }
>     $self->SUPER::_attribute_store( @_ );
>
> }

Not a bad idea.

thanks.

>
> </untested>
>
> The you would ask for
>
>     my $value = $object->{my_column_raw};
>
>
>
>
>
>
> --
> Bill Moseley
> moseley at hank.org
>
>


--
pjs




More information about the ClassDBI mailing list