morgon has asked for the wisdom of the Perl Monks concerning the following question:

Hi

I have a xml-column in a table that I inflate and deflate to an object like this:

__PACKAGE__->inflate_column('xml', { inflate => sub { MyObject->new( xml + => $_[0] ) }, deflate => sub { $_[0]->asXML }, } );
This works and I can do the following:
$row->xml(MyObject->new( xml => "<hubba/>" ); # row is now dirty $row->update; # goes to the database
Now assume the MyObject-class has a method "bubba" that changes it's state. Then this does not work:
$row->xml->bubba("whatever"); #works in memory but column is not co +nsidered dirty $row->update; # does nothing
So the problem is that calling methods on the inflated object does not make the column "dirty" for DBIx::Class.

So my question is how can I (or better the inflated object) tell DBIx::Class that the column is now dirty and should be written back to the database?

Many thanks!

Replies are listed 'Best First'.
Re: inflated columns in DBIx::Class
by CountZero (Bishop) on May 04, 2009 at 18:39 UTC
    Your bubba("whatever") method must call the make_column_dirty($columnname) method on the row.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

      Your bubba("whatever") method must call the make_column_dirty($columnname) method on the row.
      I can't because in the version of DBIx::Class (0.08013) that I am using this method does not exist (any more?).
        That method still exists: you can find it in the DBIx::Class::Row module.

        CountZero

        A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James