I have a model A that has a “has_many” association to another model B. I have a business requirement that an insert into A requires at least 1 associated record to B. Is there a method I can call to make sure this is true, or do I need to write a custom validation?
Share
You can use
validates_presence_ofhttp://apidock.com/rails/ActiveModel/Validations/ClassMethods/validates_presence_ofor just
validateshttp://apidock.com/rails/ActiveModel/Validations/ClassMethods/validates
But there is a bug with it if you will use
accepts_nested_attributes_forwith:allow_destroy => true: Nested models and parent validation. In this topic you can find solution.