gpt4 book ai didi

sql - Rails 4 中的 sanitize_sql_array

转载 作者:行者123 更新时间:2023-12-04 23:43:23 26 4
gpt4 key购买 nike

在 Rails 3 模型中,您曾经能够做到:

query = self.sanitize_sql_array(["SELECT MONTH(created) AS month, YEAR(created) AS year FROM orders WHERE created>=? AND created<=? GROUP BY month ORDER BY month ASC", created1, created2])

然而,这已从 rails for 中删除,显然已移至“ActiveRecord::Sanitization::ClassMethods”(http://api.rubyonrails.org/classes/ActiveRecord/Sanitization/ClassMethods.html#method-i-sanitize_sql_for_assignment)。但我试过调用ActiveRecord::Sanitization.sanitize_sql_array(...)我得到了错误:

undefined method 'sanitize_sql_array' for ActiveRecord::Sanitization:Module

有人可以帮我解决这个问题吗?或者提供一个更好的选项来像我试图传递的那样清理查询?谢谢!

最佳答案

试试这个..

ActiveRecord::Base.connection.select_all(
ActiveRecord::Base.send(:sanitize_sql_array,
["select created_at as month from orders where date(created_at) >= ?", '2015-12-21']
)
)

关于sql - Rails 4 中的 sanitize_sql_array,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34094129/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com