Thank you!! On Sunday, December 12, 2021 at 5:56:03 PM UTC-5 Jeremy Evans wrote:
> On Sun, Dec 12, 2021 at 2:16 PM jaso...@gmail.com <jaso...@gmail.com> > wrote: > >> I'm experimenting using SQLite with some json APIs. Since there's no >> out-of-the-box support for json columns, I'm storing loosely-structured >> data as json in a Text column using the serialization plugin: >> >> plugin :serialization >> serialize_attributes :json. :transaction_data, :other_attributes >> >> This works fine for model instances ( some_instance.transaction_data). >> But I fequently use .naked when I need a small subset of data from a lot >> of rows, but the serialization plugin doesn't seem to run when doing this. >> >> I tried doing some_dataset.all.map(&:to_hash) but ended up with the same >> thing - just json string values. >> >> I can understand the naked method pulling the data in as-is, but should >> the `to_hash` method be using the defined serialization? >> > > serialization is a model plugin, not a dataset extension. The > serialization and deserialization happen at the model layer, so if you use > naked to skip the model layer, you skip the deserialization. Also, > Model#to_hash just returns the column values (serialized), it doesn't > include the deserialized values. You may want: > > dataset.all.map do |v| > hash = v.values.dup > hash[:transaction_data] = v.transaction_data > hash[:other_attributes] = v.other_attributes > hash > end > > Thanks, > Jeremy > -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to sequel-talk+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sequel-talk/a035911f-fe1c-4192-b718-b255f11c8791n%40googlegroups.com.