我有模型结构,例如:
class User
include Mongoid::Document
include Mongoid::Alize
field :name
field :visible, type: Mongoid::Boolean
default_scope -> { where(visible: true) }
has_many :posts
end
class Post
include Mongoid::Document
include Mongoid::Alize
field :visible, type: Mongoid::Boolean
default_scope -> { where(visible: true, 'user_fields.visible' => true) }
belongs_to :user
alize :user, :visible
end
当我设置Post和User visible:true时它可以工作,但是当我在Post实例中设置visible:false时,非规范化不起作用。 我怎样才能告诉alize通过'unscoped'工作? 附:抱歉我的英语不好。