[Dbix-class] dirty-flag on inflated columns

Morgon Hed morgonhed at yahoo.com
Tue May 5 15:37:37 GMT 2009


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/>"...

Can someone explain to me what I am doing wrong?

Many thanks!



--- On Tue, 5/5/09, Matt S Trout <dbix-class at trout.me.uk> wrote:

> From: Matt S Trout <dbix-class at trout.me.uk>
> Subject: Re: [Dbix-class] dirty-flag on inflated columns
> To: "DBIx::Class user and developer list" <dbix-class at lists.scsys.co.uk>
> Date: Tuesday, May 5, 2009, 7:04 AM
> On Mon, May 04, 2009 at 09:35:08AM
> -0700, Morgon Hed wrote:
> > 
> > > Yes there is:
> > 
> > Not in my version it seems.
> > 
> > I have 0.08013 and in this version there does not seem
> to be a "make_column_dirty" method in DBIx::Class::Row (I
> just inspected the code).
> 
> You're going to need 08100+ for that method.
> 
> The inflator gets passed the value and the original row
> object, among other
> things - look at the InflateColumn docs for more info and
> if in doubt Dumper
> @_ in your inflator to get a feel for it.
> 
> As for the circular reference, Scalar::Util::weaken will
> save you here.
> 
> -- 
>         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/
> 
> _______________________________________________
> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
> Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk
> 


      



More information about the DBIx-Class mailing list