[CDBI] Help tracking down a problem w/ has_a and unexpected deflating.

Rhesa Rozendaal perl at rhesa.com
Mon Aug 29 00:46:54 BST 2005


George Hartzell wrote:
> George Hartzell writes:
>  > 
>  > I'm building a Mason based web app on FreeBSD 6-ish using perl 5.8.6
>  > and a whole passel of cpan-standard stuff (details if they're
>  > interesting).  I'm using SQLite to store my data and Class::DBI to
>  > manipulate it.  I'm using Class::DBI version 0.96 built via FreeBSD's
>  > ports system but see similar results with a copy of 0.999.
>  > [...]
> 
> I hate to reply to my own message, but I've just had an Ah-ha moment
> that might be helpful.
> 
> The columns that are working seem to be the ones that I give values
> when I create() the object.  If I take a perfectly good Project object
> that has a valid time and do this:
> 
>   $p->started_on(DateTime->now->epoch)
> 
> it is still fine, but as soon as I do a $p->update, it's value is
> inserted into the DB as a string.
> 
> Interesting?

Yes, in fact it confirmed my initial suspicion. You don't have a deflate 
method to go with the inflate, and that seems to trip you up here.

Try this instead:

__PACKAGE__->has_a(started_on  => 'DateTime',
	   inflate => sub {DateTime->from_epoch(epoch => shift);},
	   deflate => 'epoch', # the method to call on the DateTime
			       # object (if it exists)
	);

Hope that helps,

Rhesa




More information about the ClassDBI mailing list