On Thu, Aug 26, 2010 at 3:33 AM, Peter Rabbitson
<[email protected]<rabbit%[email protected]>
> wrote:
> Pavel A. Karoukin wrote:
> > 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.
> >
> > 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?
>
> Absolutely impossible, since the whole idea of InflateColumn is:
> *) A plain scalar value supplied to new/update is assumed to be an
> already-deflated value to be placed directly in the database
> *) Any type of reference (blessed or not) is a candidate for deflation
> and passed on to the deflator
>
> However you may find that FilterColumn does exactly what you want to
> do.
>
>
Peter,
Thank you for pointing to FilterColumn. I've tried it with almost same
result tho.. Probably I am doing something wrong?
I.e. I replaced __PACKAGE__inflate_column with:
__PACKAGE__->filter_column(
'data' => {
filter_to_storage => '__data_to_storage',
filter_from_storage => '__data_from_storage',
},
);
sub __data_to_storage {
my ($self, $data) = @_;
return encode_json($data);
}
sub __data_from_storage {
my ($self, $data) = @_;
return decode_json($data);
}
And now in my controller code trying this:
$c->user->data->{test}; # return "yes" as stored in DB in JSON format
$c->user->data->{test} = "no"; # now this contain "no", but not stored in
DB yet
$c->user->update(); # I thought it should pass $c->user->date to
__data_to_storage(), but it never do this. Why?
So so far it behaive the same way as InflateColumn =(
Regads,
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]