Ok so i have users and company and there a a join table on a many to many relationship
SO i can do
@user.companies
Can i do a scope that passes back the first company
i tied this in the user model
scope :first_company, includes(:companies_users).where(:user_id => self.id).first
and this fails….any suggestions
Update
I have this that will work also but i was wondering if there was a equivalent scope
def company
self.companies.first
end
You need to define your scope as a lambda as the context of self in a scope would be the class not the instance.
see this SO article for how to do that.
Ruby Lambda and Scope