gpt4 book ai didi

ruby-on-rails - rails - :joins sanitizing/substitution

转载 作者:行者123 更新时间:2023-12-04 14:52:58 25 4
gpt4 key购买 nike

是否可以以与 :conditions 类似的方式为 :joins 指定参数?

这是一个例子(sql代码无关紧要)

named_scope :threads, {
:joins => [" LEFT JOIN groups_messages gm ON messages.id=gm.message_id AND gm.group_id IN (?) ",@group_ids_array],
:conditions => ["creator_id=? AND messages.id IN (?)", current_user_id, @message_ids_array]
}

在这个例子中,:conditions 的参数会被正确插入,但对于 :joins 我会得到一个错误
 Association named '  LEFT JOIN groups_messages gm ON messages.id=gm.message_id and gm.group_id IN (?) ' was not found; perhaps you misspelled it?

什么函数用参数代替:条件?

最佳答案

您可以使用 ActiveRecord::sanitize_sql_array方法。

ActiveRecord::sanitize_sql_array ['gm.group_id IN (?)', @group_ids_array]

关于ruby-on-rails - rails - :joins sanitizing/substitution,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1524671/

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