1
Suppose the models:
class A < ActiveRecord::Base
has_many :bs
end
class B < ActiveRecord::Base
belongs_to :a
has_many :cs
end
class C < ActiveRecord::Base
belongs_to :b
end
If I want an attribute of C to be unique in the scope of B I can do this:
class C < ActiveRecord::Base
belongs_to :b
validates :atributo, presence: true,
uniqueness: { case_sensitive: false,
scope: :b_id,
message: 'precisa ser único' }
end
But how do I want him to be unique in the scope of A, when I don’t have a_id
in table C?
I will have to create more columns of references anyway, otherwise it would be very complex. In my case, in fact, I have up to 3 models cascateados. Was worth the force. =)
– user7261