validación de rails 3 sobre unicidad en múltiples atributos
Utilizo Rails 3.0.0.beta4
Quiero agregar una validación de unicidad en dos atributos, eso significa que mi modelo es válido si la pareja de 'recorded_at'
y 'zipcode'
es única.
En un atributo aquí está la sintaxis
validates :zipcode, :uniqueness => true
Gracias
170
Author: denisjacquemin, 2010-07-18
3 answers
En Rails 2, habría escrito:
validates_uniqueness_of :zipcode, :scope => :recorded_at
En los carriles 3:
validates :zipcode, :uniqueness => {:scope => :recorded_at}
Para múltiples atributos:
validates :zipcode, :uniqueness => {:scope => [:recorded_at, :something_else]}
319
Author: Christian Lescuyer,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-08-15 14:15:19
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-08-15 14:15:19
Múltiples Parámetros de Alcance:
class TeacherSchedule < ActiveRecord::Base
validates_uniqueness_of :teacher_id, :scope => [:semester_id, :class_id]
end
Http://apidock.com/rails/ActiveRecord/Validations/ClassMethods/validates_uniqueness_of
Esto debería responder a la pregunta de Greg.
93
Author: Ray,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-08-13 09:22:21
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-08-13 09:22:21
No trabajo para mí, la necesidad de poner alcance en plural
Validates_uniqueness_of: teacher_id,: scope s = > [: semester_id, : class_id]
3
Author: Jesus,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-08-07 16:57:52
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-08-07 16:57:52