I have this model:
class User < ActiveRecord::Base
belongs_to :company
def company
# Do something here
# Call the actual association (that would be usually returned by calling User#company)
end
end
I’m aware that I could use another internal name for the association but want to avoid that.
I’m pretty sure there is some kind of internal method that Rails calls when you call the plain association User#company method and I want to call it myself in my redefined User#company method here.
Thanks!
You can call
superin your method. Orassociation(:company)orassociations(:company)(I forgot which one). Or you canAlso you could rename the
belongs_to :original_company, :class_name => "Company", :foreign_key => "company_id"which I think is a better solution.