【问题标题】:Rails5 ActiveRecord error: TypeError: can't quote ArrayRails5 ActiveRecord 错误:TypeError:不能引用数组
【发布时间】:2017-03-11 23:44:47
【问题描述】:

我正在尝试检查是否有预先存在的更新。

字段是receiveing_account_id,看起来像

["1", "3", "4"]

我的查询是

if Update.where("band_id = ? and fan_id = ? and receiving_account_id = ? and response = ?", "#{@remove_member.band_id}", "#{@remove_member.fan_id}", "#{[@remove_member.receiving_account_id]}", "none").any?

我已经尝试了“#{@remove_member.receiving_account_id} 的所有变体,我得到了一些格式错误的数组文字版本。

编辑:如果我去

[@remove_member.receiving_account_id]

在查询中,我得到类型错误。如果我这样做了

receiving_account_id && ARRAY[?]

我明白了

receiving_account_id && ARRAY['["1", "3", "4"]']

我认为这意味着包含在数组中,好像数组包含该数组,所以找不到它。

【问题讨论】:

  • 删除引用 ARRAY['["1", "3", "4"]'] -> ARRAY[["1", "3", "4"]]
  • 不,Rails/Active 记录如何解释接收帐户 ID && ARRAY[?]

标签: activerecord ruby-on-rails-5


【解决方案1】:

调查显示...

Update.where("receiving_account_id && ARRAY[?]", @remove_member.receiving_account_id).any?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-09
    • 1970-01-01
    相关资源
    最近更新 更多