Monday, 26 August 2013

Update serialized fields without validation?

Update serialized fields without validation?

class Foo
store :custom_fields, accessors: [:bar1, :bar2, :bar3]
validates :bar1, presence: true
validates :bar3, presence: true
end
foo = Foo.new
foo.bar1 = 'hello'
foo.bar2 = 'hello again'
foo.save(validate: false) # => foo is now saved in the database
foo.update(bar2: 'an update to bar2') # => ERROR! since bar3 fails validation
Is there anyway to update without validating? I found the update_columns
method but it doesn't seem to work with serialized data like Active Record
Store.
The alternative is to call foo.save(validate: false) every time, but I
really want to update my data instead of inserting a new record every
time.

No comments:

Post a Comment