-
Notifications
You must be signed in to change notification settings - Fork 71
Have any option set new value default to true? #62
Comments
Hi @zlx! I'm pretty sure you can use the default option for new models. Does that not work for your case? |
@braddunbar Does the default option also work with the legacy data, which exist before change the bitmask settings. I find it just define an after_initialize, am I missing something? Thanks |
No, but I assume that you would pair this with a migration. If that doesn't work you could probably add the value in your own |
You are right, But in my scenario, the new added value is always default true, while the default behaviour is false, so if it can be config, we needn't create migrate every time, especially when the legacy data is large, the job is so hard. I will try to make a patch for this |
Well, I noticed in your migration you're calling save on each model. User.find_each do |u|
u.push_settings << :push2
u.save
end This will take forever. Instead, I'd recommend doing this via User.update_all('users.push_settings = users.push_settings | 4') This will likely satisfy your speed requirements and obviate the need for the |
Good method, I also make a pull request for this option, hope can help somebody like me |
Let's look an example:
Suppose we have an attribute push_settings config as below
now we need to add a new push setting and default is true, we must first add it into as array:
and run an task to migrate all exists data like below:
_And in this case, almost every time add new push, it will default to be true(means it will always push)._
_So there are any option can support it?_, it seems
when you add new push, eg: :push2, without migration the exists data it default will be true, such as
The text was updated successfully, but these errors were encountered: