I want to basically list out all the books by authors with names like 'jim' - prefer to have this paginated so that I can use my basic paginated list view. However, this throws up an exception:
Mysql::Error: Unknown table 'books' in where clause: SELECT count(*) AS count_all FROM books WHERE (author.name like '%ha%')
My models:
authors have_many books
book belongs_to author
I'm sorry I seem very confused about how to do the query. I'd appreciate help!
hi,
I'm working on a book app to !
thats how it should look like :
--->> paginate(:book, :include=>[:author], ...,
:conditions=>["authors.name like ?", '%jim%'])
the include statement operates a join in the sql query. See eager
loading for more explanations.
hi,
I'm working on a book app to !
thats how it should look like :
--->> paginate(:book, :include=>[:author], ..., :conditions=>["authors
like ?", '%jim%'])
the include statement operates a join in the sql query. See eager
loading for more explanations.
Thanks! I actually _just_ figured that out and was going to mail out a reply to my own post.
I guess my confusion came from the fact that I had not found a good example of a join query. Also, the impression that I had got from somewhere was that ":include" is used to load all the data in a single query (which stuck in my mind as an 'optimization' rather than a must-do). My rules for optimization require me to do that only at the end. Hence, it was failing.. but I understand now!
Thanks again & sorry for the bother.
Cheers
Mohit.