-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
-
Labels:None
In order to save space on default field values I've overridden methods in my models to ensure nil values return a default values when read. This works find for all types but Array. When I try to push a new value to the array the new value isn't being set.
Given the following model:
class User field :friend_ids, type: Array def friend_ids read_attribute(:friend_ids) || [] end end
When running the following in the console you can see how friend_ids isn't being set properly.
> u = User.new > u.friend_ids => [] > u.friend_ids << '123' => ["123"] > u.friend_ids => []
Is there a better way of dealing with this situation or is it a bug that can be fixed?