Module: NestedAttributesUniqueness
- Defined in:
- lib/nested_attributes_uniqueness/validator.rb,
lib/nested_attributes_uniqueness.rb,
lib/nested_attributes_uniqueness/version.rb
Overview
This module also provides uniqueness validation for nested_attributes which are associated with a tree polymorphic association. It assumes that the tree polymorphic table uses container and component as the name of the polymorphic attributes
USAGE
class Form < ActiveRecord::Base
has_many :form_contents, as: :container
# Ensures replies have unique content across post
validates_uniqueness_in_memory_for_polymorphism :form_contents, :sub_form_group, :sub_forms, :name
end
class FormContent < ActiveRecord::Base
belongs_to :container, polymorphic: true
belongs_to :component, polymorphic: true
end
class SubFormGroup < ActiveRecord::Base
has_many :form_contents, as: :component
has_many :sub_forms
end
class SubForm < ActiveRecord::Base
belongs_to :sub_form_group
has_many form_components, as: :container
end
Defined Under Namespace
Modules: Validator
Constant Summary collapse
- VERSION =
"0.1.1"