I have a model class that has these associations
class Description < ActiveRecord::Base
belongs_to :description
belongs_to :cluster
and this check rule:
validates_presence_of :cluster_id
The description association is an association to itself to do
parent/child relationships.
If I do something like
d1 = Description.new
d2 = Description.new
d2.description = d1
d2.cluster = …find a cluster…
d2.save!
d1.cluster = …find a cluster…
d1.save!
the association isn’t saved but save! doesn’t fail. If instead I do:
d1 = Description.new
d2 = Description.new
d2.description = d1
d2.cluster = …find a cluster…
d1.cluster = …find a cluster…
d2.save!
d1.save!
it works.
I’m guessing this is a bug. save! should not allow saving the child if
it couldn’t save the parent, since it silently breaks the connection.
Pedro.