I have a model, Property, that has_many_polymorphs. The associated join
table (labellings) has fields:
id (simple record id),
property_id,
labellable_id
labellable_type.
It’s basically the same system used with acts_as_taggable, except that
Property objects are a tree instead of a simple list (which doesn’t have
any bearing on this problem, i think).
If i add a property to an object then a join table entry is created. If
i add it again, i now have the object labelled twice with the same
property, which i don’t want. I could say
Actually my syntax (validates_uniqueness_of :property_id, :scope =>
[:labellable_id, :labellable_type]) is correct, but i want it to simply
fail to save, rather than raise an exception. Does anyone know how to
do this?
Actually my syntax (validates_uniqueness_of :property_id, :scope =>
[:labellable_id, :labellable_type]) is correct, but i want it to simply
fail to save, rather than raise an exception. Does anyone know how to
do this?
instead of model.save! or model.update!, use the form
instead of model.save! or model.update!, use the form
if model.save
my model was saved successfully
else
my model didn’t save
end
Thanks Ilan - i played around with this a bit more and narrowed my
problem down a bit. It’s actually only the << (push) operator that
breaks horribly - save just quietly fails, which is what i want. So, as
a way of adding a label (join table entry) to an object (eg of class
Lesson) this works fine (ie fails without raising):