mysql - Validating Uniqueness within data in another Table -
i have student , student_section model. student table have student_id , roll_no, student_section have student_id, standard_id , section_id.
roll_no should unique in standard , section.
in student.rb file i'm having trouble setting custom validation roll_no unique in standard , section present in student_section model.
i'm having trouble implementing, can help?
if using rails 4, can define relation of model , if true, duplcates omitted collection.
has_many :student_sections, -> { uniq }, through: :students and if using rails < 4 version, try this
has_many :student_sections, :through => :students, :uniq => true
Comments
Post a Comment