0

I was looking for a good way to store user preferences in PostgreSQL, and came across this article on Medium.

store_attributes :preferences do
  subscribed_to_newsletter Boolean, default: true
  wants_reminders Boolean, default: true
  wants_deals_offers Boolean, default: true
end

For the most part this works really well. But now I would like to expand on this and I would like to add in more details.

So in the DB the data is stored in an array...

{
  "wants_reminders": true,
  "wants_deals_offers": true,
  "subscribed_to_newsletter": true
}

But I would like to add another level to this

{
"wants_reminders": true,
"wants_deals_offers": true,
"subscribed_to_newsletter": true,
"Something_here": {
    "Option1": "data",
    "Option2": "data"
}

}

Does anyone know how I would go about adding in this extra level to the JSON data? Or at least point me to a resource which would help.

Alan
  • 459
  • 6
  • 20
  • 1
    Have you looked at https://stackoverflow.com/questions/36926927/use-storext-or-just-virtus-with-nested-array-or-hash-objects? It seems that you can't do that with Storext. I would try looking directly into ActiveRecord::Store: https://api.rubyonrails.org/classes/ActiveRecord/Store.html ). – benj-p May 19 '20 at 11:47
  • Cheers @benj-p much appreciated I didnt see that post. – Alan May 19 '20 at 12:21

0 Answers0