Rails: Validate unique combination of 3 columns

There is a syntax error in your code snippet. The correct validation is :

validates_uniqueness_of :car_model_name, :scope => [:brand_id, :fuel_type_id]

or even shorter in ruby 1.9.x:

validates_uniqueness_of :car_model_name, scope: [:brand_id, :fuel_type_id]

with rails 4 you can use:

validates :car_model_name, uniqueness: { scope: [:brand_id, :fuel_type_id] }

with rails 5 you can use

validates_uniqueness_of :car_model_name, scope: %i[brand_id fuel_type_id]

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)