Hello,

I am trying to make something work nice, but it doesn't want to =) Probably,
it's just by design, or I am missing something.

I have text column in DB used to store everything not fit into row
initially. To do this - I am storing serialized hash in JSON format.

In Result class I have something like this:

__PACKAGE__->table("users");
__PACKAGE__->add_columns(
 [...]
  "data",
  {
    data_type => "TEXT",
    default_value => undef,
    is_nullable => 1,
    size => 65535,
  },
);

use JSON::XS;
use Hash::AsObject;

__PACKAGE__->inflate_column(
    'data',
    {
      inflate => sub {
        Hash::AsObject->new(decode_json( shift() ))
      },
      deflate => sub {
        encode_json shift
      },
    },
);


It works well for retrieving values from DB:
$test = $user->data->{test}; # return 1

But to save data in db I want to do following:
$user->data->{test} = 1;
$user->update();

This doesn't work. It successfully assign 1 to $user->data->{test}, but it
never passes to deflator and never stores in the DB.

But in the same time this works without any problems:
$user->data({ 'test' => 1 });
$user->update;


Question: is it possible to make it work with $user->data->{test} = 1;
notation? I.e. I do not want to create new methods in results class, not
want to extract hash from field first and then save it?

Regards,
Pavel
_______________________________________________
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/[email protected]

Reply via email to