Rails 3中ActiveRecord的:UNION [英] Rails 3 ActiveRecord: UNION

查看:456
本文介绍了Rails 3中ActiveRecord的:UNION的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法使用MySQL UNION在Rails的3?

Is there any way to use MySQL UNION in Rails 3?

推荐答案

我觉得只有这样,你会得到这个直接执行的查询工作。

I think the only way you're going to get this to work by directly executing the query.

ActiveRecord::Base.connection.execute("SELECT REPEAT('a',1) UNION SELECT REPEAT('b',10)")

这将返回一个ActiveRecord的结果集。如果你想包在一个模型的结果做这样的事情:

This returns an ActiveRecord resultset. If you want the results wrapped in a model do something like this:

MyModel.find_by_sql("...")

这篇关于Rails 3中ActiveRecord的:UNION的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆