I have an application which defines some models. I want to extend the functionality of some models(eg. adding methods,adding associations) from application to my engine. I tried adding a model in the engine with the same name as my application's model and Rails will automatically merge them, however it doesn't work.
eg: (Application's model)
class Article < ActiveRecord:Base
def from_application
puts "application"
end
end
(Inside my Engine)
module MyEngine
class Article < ::Article
has_many :metrics, :class_name => 'Metric'
end
end
has_many association is not getting applied to my Articles model when I try to access @articles.metrics. Any ideas ?
Do you have your metrics model have a belongs_to association with Articles.
You might want to give the other side of the association, Metrics a belongs_to Articles to have this work properly. Also, make sure to have a migration to hold articles_id on the metrics table. Everything should work fine.