Querying Named Scopes Across Models with ActiveRecord::Relation#merge Discussion
Great tip, Chris! Thanks for sharing. However, I notice (at 2:53) that your query `Author.joins(:books).merge(Book.available)` returns the same author three times. I'm not a SQL pro, so perhaps that's the normal behavior for this query, but not what I would expect when trying to return "all of the authors that have an available book". Any suggestions for de-duping the results from `merge()`? I'm sure a `uniq()` on the end would do the trick, but wonder if ActiveRecord has a way to do this right in the DB.
Hello, Chris! Thank you for your education!
I try make it by using association at DataBase. So i use:
And its work! Whats way is better (merge or method above )?
P.S. Sorry for my English.