0
我有一个类,但我想要一些自定义的行为,如果一个字段是一个特定的值。否则,我想要默认行为。呼叫默认的mongoid函数
class Foo
include Mongoid::Document
belongs_to :parent, :foreign_key => "parent_id", :class_name => "Pad"
has_many :children, :foreign_key => "parent_id", :class_name => "Pad"
field :bar, :type => String
def children
if self.bar == "some value"
# Do something special
else
return self.children # <- What goes here that isn't an infinite loop?
end
end
end
else分支应该是什么?
我不想重新实现孩子,所以我正在寻找的不仅仅是Foo.where(:PARENT_ID => self.id)