ruby on rails - RoR validations -- conditions being ignored? -
I am trying to get a model to verify the specificity of a column when two criteria are met - published True, and demoted is wrong if any of these things are the opposite, do not save the model. Right now, it is stopping duplicates regardless of the values of these columns.
I have a model:
article --- ---- name: string description: string value: string value_hash: string published: bool Derecated: bool Here's its class:
class article & lt; ActiveRecord :: Base is_to: User validates_presence_of: Name, Description, Values validates_uniqueness_of: checksum, Terms: - & gt; {Where (published: true). Where (Deprecated: Incorrect)}, Message: "Already exists." Before_save: hash_article_value def heh_article_value self.checksum = digest :: SHA1.hexdigest (self.value) end and Therefore, if one saves the article, and it is not published, then Mike Saves the same article and publishes it, it should allow Mike to do so. Who will then try to publish the same article and this singularity will fail the barrier.
Issue: Now, if he saves unpublished articles, Mike can not publish the exact same article (Specification hinders failed)
Why does this fail when I specify conditions in validates_uniqueness_of?
You can use checksum by using first_save < / Code> calculate the callback, so you have zero checksum while verification runs before_validate callback
Comments
Post a Comment