in ActiveRecord::Base validations
Select multiple columns in uniquness and
Also, is it possible to add the value of the column to the conditions?
What do you want to be uniquness?
- user_id
- mst_category_id
- In addition, active=true
I thought it was like this, but it was completely different...
class User<ActiveRecord::Base
values:user_id,
unity: {
scope:[:mst_category_id, active:true]
}
I didn't save it, but according to the reference,
validates:user_id, unique:{scope::mst_category_id}, conditions:->{where(active:true)}
There seems to be a way to write (conditions
).
© 2024 OneMinuteCode. All rights reserved.