When I manually assign a parent to a child like this:
parent = create :rule # I'm using FactoryBot to create test data
child = create :rule, parent: parent
Then the parent doesn't know about it:
parent.children # => []
How can I make sure that the parent gets to know about the new child? At the moment, I manually assign the child to the parent:
parent.children << child
But this feels quirky. Is there a better way of doing it?
In your factory:
This will let you call from your spec:
And will create both your parent and child in one line, or if you need both assigned to a varaible: