acts_as_tree
acts_as_tree copied to clipboard
Bug with `leaf?` method
leaf?
method given me exception:
TypeError: nil can't be coerced into Fixnum from /usr/local/bundle/gems/activerecord-5.0.0.1/lib/active_record/associations/collection_association.rb:319:in `+'
I have the same error with this:
model.association.children.size.zero?
Can we change implementation of leaf?
https://github.com/amerine/acts_as_tree/blob/4fa898054e7b01962ec4b65919c844ee95554fa2/lib/acts_as_tree.rb#L352
method from:
def leaf?
children.size.zero?
end
to:
def leaf?
children.blank?
end
?
Video: https://youtu.be/hutkAa39JcU
This is strange, because children
should be a has_many
association, which cannot return nil
.
Maybe you have a method on your model that overrides the default children
association?
I have not method that overrides this chilldren association. My first idea was eager loading
in ActiveRecord - my video present this behavior.
This sounds similar to the ActiveRecord bug described in issue rails/rails#28579.
Could you try if the bug is fixed by using rails master?
Bug is fixed in rails#master