Rails always include (join) on initialize
- by Seth
Hello, I have a User model as illustrated below:
class User < ActiveRecord
belongs_to :college
belongs_to :class_level
end
I want to ALWAYS join with those other two tables returning one simplified User object. How do I accomplish this in my User model. I'm aware that I can do this in another model:
class Foo < ActiveRecord
has_many :users, :include => [:college, :class_level]
end
But I want to do this in my User model, so Foo.users will either be eager loaded OR be joined already. Is there a way to create an initialize this in the User model?