Based on a quick search, you could use :inverse_of
to overcome this situation.
In your code:
class Parent
has_many :cars, inverse_of: :parent
accepts_nested_attributes_for :cars
end
class Car
belongs_to :parent
validates :parent, presence: true
end
(not tested)
Check out dem sources:
- Validating presence of the parent object (scroll to that part).
- Issue on github
- Some post I didn't bother to read but is referenced on the issue above
GL & HF.