[Dbix-class] dirty-flag on inflated columns

Matt S Trout dbix-class at trout.me.uk
Mon May 11 17:19:56 GMT 2009


On Tue, May 05, 2009 at 08:37:37AM -0700, Morgon Hed wrote:
> 
> Ok - I've updated to 0.08102 and now I have a make_column_dirty but it does not seem to work.
> 
> Here is what I do for trying it out:
> 
> I have a class "SMU::Wrapper" that simply wraps some xml, it has an accessor "stuff" that allows me to get/set the wrapped xml.
> 
> I now inflate/deflate column "xml" like this:
> 
> __PACKAGE__->inflate_column('xml',
>                                   {
>                                    inflate => sub { SMU::Wrapper->new( stuff => $_[0], row => $_[1], column => "xml" ) },
>                                    deflate => sub { $_[0]->stuff },
>                                   }
>                            );
> 
> 
> Now I do a search and a find like this:
> 
> my $rs = $schema->resultset('Stream')->search(
>                                                {},
>                                                    {
>                                                      select => [ 'id', { 'xmltype.getCLobVal' => 'xml' } ],
>                                                      as     => [qw/id xml/],
>                                                    }
>                                              );
> 
> 
> my $s = $rs->find(1);
> 
> This allows me to retrieve my object representing primary key 1 with inflated column, so far so good.
> 
> I can now do the following:
> 
> print $s->xml->stuff; # this prints the correct xml read from the db
> 
> $s->xml->stuff("<hubba/>");   # now I change it
> 
> print $s->xml->stuff;      # print it again to verify it really has changed (in memory)
> 
> $s->make_column_dirty('xml');
> 
> $s->update;
> 
> SMU::Schema->commit;
> 
> Now I trace with DBIC_TRACE=1 and I can see that indeed the call to make_column_dirty results in an update to the database, but unfortunately it is not updated to the new value I have set it to but again to the old value it had in the database before I changed to "<hubba/>"...

Oh FFS, that's not triggering the deflate of course.

I suspect what you actually want for the moment is:

$s->xml($s->xml);

Thoughts on whether make_column_dirty should clear the deflated value if an
inflated one is present, guys?

-- 
        Matt S Trout         Catalyst and DBIx::Class consultancy with a clue
     Technical Director      and a commit bit: http://shadowcat.co.uk/catalyst/
 Shadowcat Systems Limited
  mst (@) shadowcat.co.uk        http://shadowcat.co.uk/blog/matt-s-trout/



More information about the DBIx-Class mailing list