Description
Hi,
After installing the closure_tree
gem (with bundler) and adding the acts_as_tree
line to my model (and performing the associated migrations), I get the following error when attempting to create a node. (The model I'm attempting to use closure_tree
with in this case is called Item
):
> Item.create merchant_item_id: 1, name: "lol"
NoMethodError: undefined method `find_each' for []:Array
Did you mean? find_all
from /Users/antondewinter/.rvm/gems/ruby-2.4.2/gems/closure_tree-6.6.0/lib/closure_tree/hierarchy_maintenance.rb:85:in `block in rebuild!'
merchant_item_id
is a required field in the model (and I think is unrelated to this error). When I first tried to create a node, the item_hierarchies
table was empty.
I tried to trace this error to a recent change in the closure_tree
codebase, and I think it is related to this commit. Which sort of makes sense: when there are no children, an empty array is returned (instead of an AR association), meaning one cannot use #find_each
; which would cause this error. When I modified Line 85 back to just using regular .each
, there were no errors and I was able to create nodes.
Is this a bug or am I doing something wrong?
Thanks!