0
如何编写子查询在这样的Rails?:如何在Rails中编写多个COUNT(*)子查询?
select
m.field1,
m.field2,
(select count(*) from details1 d1 where d1.id=m.field3) as count1,
(select count(*) from details2 d2 where d2.id=m.field4) as count2,
(select count(*) from details3 d3 where d3.id=m.field5) as count3
from
master m
数据库服务器是PostgreSQL的。
NoMethodError:未定义的方法'set_table_name”硕士:类(Rails的3.2.3) – Paul
看来这个选择本身能够接受一个任意SQL字符串。谢谢你的线索。我自己的书签:http://stackoverflow.com/questions/10374105/using-raw-sql-queries-in-rails-3-application – Paul
应该包含来自AR的继承。我会编辑我的答案。 –