Reputation: 5104
Please note that I understand I could do the following in a single SQL query that's not the point of the question however... I'm more curious about how rails deals with multiple queries.
Let's say I have a Movies model with attributes such as title, director, id, star, release date, etc.
Now I have @Movies = find_by_sql("select * from movies where genre='Action';select * from movies where genre='Comedy';")
And I iterate through it on the view. However only the first query results seem to be contained in the answer. Just curious about how this works.
Thanks
Upvotes: 0
Views: 788
Reputation: 25994
This should work
@Movies = find_by_sql("select * from movies where genre='Action' or genre='Comedy';")
Edit: this is maybe what you're refering to with the single query.
Another way to do it is
find_by_genre('Action') << find_by_genre('Comedy')
Upvotes: 1