Hello,<div><br></div><div>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.</div><div><br></div><div>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.</div>
<div><br></div><div>In Result class I have something like this:</div><div><br></div><div><div>__PACKAGE__->table("users");</div><div>__PACKAGE__->add_columns(</div><div> [...]</div><div> "data",</div>
<div> {</div><div> data_type => "TEXT",</div><div> default_value => undef,</div><div> is_nullable => 1,</div><div> size => 65535,</div><div> },</div><div>);</div><div><br></div><div><div>
use JSON::XS;</div><div>use Hash::AsObject;</div><div><br></div></div><div>__PACKAGE__->inflate_column(</div><div> 'data',</div><div> {</div><div> inflate => sub {</div><div> Hash::AsObject->new(decode_json( shift() ))</div>
<div> },</div><div> deflate => sub {</div><div> encode_json shift</div><div> },</div><div> },</div><div>);</div><div><br></div><div><br></div><div>It works well for retrieving values from DB:</div>
<div>$test = $user->data->{test}; # return 1</div><div><br></div><div>But to save data in db I want to do following:</div><div>$user->data->{test} = 1;</div><div>$user->update();</div><div><br></div><div>This doesn't work. It successfully assign 1 to $user->data->{test}, but it never passes to deflator and never stores in the DB.</div>
<div><br></div><div>But in the same time this works without any problems:</div><div>$user->data({ 'test' => 1 });</div><div>$user->update;</div><div><br></div><div><br></div><div>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?</div>
<br>Regards,<br>Pavel <br><br>
</div>