Mysql rails3中的activerecord不会返回联接表中的多个列
我有一个查询,在mysql cli中运行时会给出正确的结果,但在rails执行时不会 查询:Mysql rails3中的activerecord不会返回联接表中的多个列,mysql,ruby-on-rails,activerecord,join,ruby-on-rails-3.1,Mysql,Ruby On Rails,Activerecord,Join,Ruby On Rails 3.1,我有一个查询,在mysql cli中运行时会给出正确的结果,但在rails执行时不会 查询: SELECT t1.id, t1.event_id, t2.content, t2.created_at, t3.title FROM t1 INNER JOIN t2 ON t2.id = t1.event_id INNER JOIN t3 ON t3.id = t2.id WHERE (t1.id in (SELECT id FROM t4 WHERE attr = 20)) ORDER B
SELECT t1.id, t1.event_id, t2.content, t2.created_at, t3.title FROM t1
INNER JOIN t2 ON t2.id = t1.event_id
INNER JOIN t3 ON t3.id = t2.id
WHERE (t1.id in (SELECT id FROM t4 WHERE attr = 20))
ORDER BY t1.created_at DESC
LIMIT 15
我曾经
t1.find_by_sql "<above_sql_query>"
t1.find\u by\u sql“”
但它只返回与t1有关的列。结果是一个数组:
[#<t1 id: 3, event_id: 3>]
[#]
我也试过了
t1.find(:all, :select => "<select attributes as above>", :joins => "as above", :conditions => "as above", :limit => 15, :order => "t1.created_at DESC")
t1.find(:all,:select=>“”,:joins=>“如上所述”,:conditions=>“如上所述”,:limit=>15,:order=>“t1.created\u at DESC”)
但是仍然给出相同的结果,只返回与t1有关的属性。请帮助我找到执行该命令的最佳方法
谢谢,pR使用
.includes
为我解决了这个问题。使用.includes
为我解决了这个问题