OK So I've got my models like so:
Team
has_many :users, :through => memberships
User
has_one :user_status
Now in my Team model I want to be able to find the maximum 'updated_at'
value of my 'user_status'
models.
I tried doing something like:
Team
has_many :users, :through => :memberships
has_many :user_statuses, :through => :users
def max_last_updated_status
user_statuses.maximum(:updated_at)
end
but that gave me:
Invalid source reflection macro :has_one for has_many :user_statuses, :through => :users. Use :source to specify...
So I was wondering if there's a better way of doing this, can I just create a property of the User model like:
def status_updated_at
user_status.updated_at
end
and then change my Team class to have:
def max_last_updated_status
user.maximum(:status_updated_at)
end
? I'm assuming not as 'status_updated_at'
is not really a column and so the sql generation would fail...
Another perspective on this problem would be much appreciated.