0

この協会に問題があります。

前:

has_many  :membership, class_name: 'Profile', conditions: "profiles.role != 'owner'"

現在、属性「役割」は文字列ではなく、配列になっているため、「役割」が ['所有者'] ('所有者' ではない) であるレコードになる条件を変更する必要がありますが、配列を使用することはできません。試合。

欲しかった:

has_many  :memberships, class_name: 'Profile', conditions: "profiles.role != ['owner']"

プロファイル モデル

class Profile < ActiveRecord::Base
  attr_accessible :role

  serialize :role, Array
  belongs_to :account

  def roles?(role)
    role.include?(role)
  end
end
4

2 に答える 2

0

解決策を見つけました。正しいクエリは次のとおりです。

`profiles`.`role` NOT LIKE '%owner%'

アレルの使用:

Profile.arel_table[:role].does_not_match('%owner%').to_sql

結果:

profiles`.`role` NOT LIKE '%owner%

列タイプ「文字列」がシリアル化されていても、これは検索用のSQLにとって「文字列」のままだと思います。しかし、繰り返しますが、これは仮定です。

于 2013-05-31T14:57:55.993 に答える