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?
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?
Mysql::Error: #42S02Unknown table 'book' in field list: SELECT
sum(book.score) AS sum_book_score FROM users LEFT OUTER JOIN books ON
books.user_id = users.id ORDER BY score desc
It works! Thank you so much! So is the key that the foreign key
needs to be specified on both sides of the association? Is the books
model being done correctly as is?
It works! Thank you so much! So is the key that the foreign key
needs to be specified on both sides of the association? Is the books
model being done correctly as is?
Thanks again,
R
Yeah apparently it does, though the examples in AWDR don't do it that way for some reason.
For the Book model you can try:
book = Book.find(1)
book.user
and it should give you back the user for that book.