[英]Convert rails activerecord to raw sql
In php codeigniter FW, I can do it easily by using get_compiled_select() method. 在php codeigniter FW中,我可以使用get_compiled_select()方法轻松地做到这一点。
Is there any method that I can convert the query build by active record to raw sql. 有什么方法可以将活动记录的查询构建转换为原始sql。 Ex:
例如:
User.find_by_name("abc")
should return raw query script something like 应该返回原始查询脚本,例如
select * from user where name = "abc"
You can use to_sql
(it gives you a sql query string, and can be called on any ActiveRecord association): 您可以使用
to_sql
(它为您提供sql查询字符串,并且可以在任何ActiveRecord关联上调用):
User.find_by_name("abc").to_sql
http://apidock.com/rails/ActiveRecord/Relation/to_sql http://apidock.com/rails/ActiveRecord/Relation/to_sql
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.