开发者

Dealing with multiple SQL queries within single find_by_sql

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 i开发者_开发知识库t on the view. However only the first query results seem to be contained in the answer. Just curious about how this works.

Thanks


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')


Try the UNION SELECT... sql query...

Also, LOL cs142?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜