我正在使用 User.delete_at 在我的应用中启用用户软删除。设置该字段后,我不希望在整个应用程序中返回已删除的用户。因此,鉴于我有以下模型,我设置了以下内容:
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 用户不会在整个应用程序中返回?谢谢