开发者

Rails STI validation inheritance

开发者 https://www.devze.com 2023-02-04 04:05 出处:网络
I have STI model开发者_如何转开发s in my Rails application. The ancestor model has validations with the validates_... methods which are working fine.

I have STI model开发者_如何转开发s in my Rails application. The ancestor model has validations with the validates_... methods which are working fine.

But I have custom validations as well, and I would like to add more different custom validations in the descendants. These custom validations would depend on the class.

If I write

class DescendantA < Ancestor

  protected
    def validate
      # ...
    end
end

It simply overwrites the original validations, so I loose the original inherited validations.

Is there a convention to do this in Rails?


Would it not be sufficient to add super at the end of the validate method in the child, so that the parent's validate method would also be called?

0

精彩评论

暂无评论...
验证码 换一张
取 消