Could someone please explain to me how to do use the ActiveRecord
helpers to do calculations with joins on renamed foreign keys?
:class_name => ‘User’,
:foreign_key => ‘created_by’
I’m trying to calculate a list of the users by summed book scores,
with the following code.
@users = User.sum(‘books.score’, :include => ‘books’)
I’m getting the error: 42S22Unknown column ‘books.user_id’ in ‘on
clause’. Isn’t Rails supposed to be smart enough to realize that the
foreign key has been renamed? How do I tell it to use created_by as
the foreign key here?