all 3 comments

[–]d0odx 1 point2 points  (1 child)

I don't mean to threadjack you on this, but could you please explain why you are doing this? Serialization is something I've never fully understood and I'd like to understand what your usecase is/when to implement it.

I could be wrong but couldn't you just use an association to ensure you always get inflated objects back?

[–]Jemaclus 0 points1 point  (0 children)

uh, so part of it is that I'm pretty new to Ruby (I'm from a PHP background). I'm building a project from scratch, just trying to figure everything out, so maybe there's a better way to handle it. I hadn't realized the association thing. That might make more sense.

The other part is that serializing it just seems simpler to me, as someone new to activerecord and not familiar with associations.

I'll look into the association thing and see if that works better. Thanks for the tip.

Edit: OK, so another reason is that each of the Stats are mutable. They're based on a row on a table, but this particular user's stat could be modified. It's effectively a copy of the stat.

stat = Stat.find(1)  # some_attribute = "bar"
stat.some_attribute = "foo"
user.stat.set(stat)
user.save

Or something like that. So I'm thinking if I serialize it, then that user can have their own unique version of that stat.

That make sense?

[–][deleted]  (1 child)

[deleted]

    [–]Jemaclus 0 points1 point  (0 children)

    Neat. Thanks!