has_a to non-CDBI objects

[prev] [thread] [next] [Date index for 2005/02/14]

From: Carl Johnstone
Subject: has_a to non-CDBI objects
Date: 10:35 on 14 Feb 2005
Hi,

Been playing around with a custom object that I want to expand a database 
column into. As far as I'm able to tell, CDBI will not update if I only make 
changes in this custom object.

Looking at the code it comes back to the is_changed method which only checks 
__Changed for each column. This never gets set for non-CDBI has_a fields.

I've worked around it by using a couple of triggers in my CDBI object, - the 
first captures the stringified value of the column after loading, the second 
sets __Changed accordingly if it's different at the time I want to do the 
update:

__PACKAGE__->add_trigger(
  select => sub {
    my $self = shift;
    $self->{_init_scratchpad} = $self->scratchpad->_stringify;
  },

  before_update => sub {
    my $self = shift;
    $self->{__Changed}{scratchpad}++ if ( $self->{_init_scratchpad} ne 
$self->scratchpad->_stringify);
  },

);

It would be nicer if this functionality was there by default, and worked in 
the is_changed (and any_changed) methods. I'd suggest the option of passing 
a is_changed method the same way you pass in your inflate/deflate methods. 
With the default being to do the same as above and store the initial 
deflated value for later comparison.

Carl

has_a to non-CDBI objects
Carl Johnstone 10:35 on 14 Feb 2005

Re: has_a to non-CDBI objects
Charles Bailey 15:06 on 14 Feb 2005

Re: has_a to non-CDBI objects
Perrin Harkins 20:43 on 14 Feb 2005

Generated at 10:23 on 16 Feb 2005 by mariachi v0.52