[英]Rails Translate SQL raw in ActiveRecord
I have this SQL query我有这个 SQL 查询
sql = "select mt1.* from mail_templates as mt1 join mail_templates as mt2 where mt1.template_id = mt2.id AND mt1.technical_name='#{name}' AND mt2.festival_id=#{festival}"
If I execute this query with ActiveRecord::Base.connection.execute(sql).first
it returns an array and I need to have a MailTemplate ActiveRecord.如果我使用
ActiveRecord::Base.connection.execute(sql).first
执行这个查询,它会返回一个数组,我需要一个 MailTemplate ActiveRecord。
I don't know how to do it.我不知道该怎么做。
Thanx for your help感谢您的帮助
I found the solution by using我通过使用找到了解决方案
sql = "select mt1.* from mail_templates as mt1 join mail_templates as mt2 where mt1.template_id = mt2.id AND mt1.technical_name='#{name}' AND mt2.festival_id=#{festival}"
MailTemplate.find_by_sql(sql)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.