Extend model in plugin with “has_many” using a module

后端 未结 3 879
挽巷
挽巷 2021-02-10 08:28

I have a some code in an engine style plugin which includes some models. In my app I want to extend one of these models. I have managed to add both instance and class methods to

3条回答
  •  一生所求
    2021-02-10 09:35

    You should be able to do this. A little more concise IMHO.

    module Qwerty::Core::Extensions::User
      def self.included(base)
        base.class_eval do
          has_many  :hits, :uniq => true
          before_validation_on_create :generate_code
        end
      end
    end
    

提交回复
热议问题