1
我正在使用User.delete_at在我的應用程序中啓用用戶軟刪除。當設置該字段時,我不希望刪除的用戶在整個應用中返回。所以我設置了以下給出我有以下型號:ActiveRecord錯誤:缺少表「用戶」的FROM子句條目
User.rb
has_many :groups, :through => :group_members, :conditions => ['banned = ?', false]
default_scope :conditions => 'users.deleted_at IS NULL'
Group.rb
belongs_to :user
has_many :group_members, :dependent => :destroy, :include => :user, :conditions => ['banned = ?', false]
GroupMember.rb
belongs_to :group
belongs_to :user
default_scope joins(:user).where('users.deleted_at IS NULL')
那麼現在的問題是,當我運行:
current_user.groups
我收到以下錯誤:
Group Load (0.5ms) SELECT "groups".* FROM "groups" INNER JOIN "group_members" ON "groups"."id" = "group_members"."group_id" WHERE "group_members"."user_id" = 1 AND (users.deleted_at IS NULL) AND (banned = 'f')
PG::Error: ERROR: missing FROM-clause entry for table "users"
LINE 1: ..."group_id" WHERE "group_members"."user_id" = 1 AND (users.dele...
有一個更好的方式使User.delete_at用戶不會被返回到整個應用程序?由於
在哪種模式? – AnApprentice