Skip to content

Instantly share code, notes, and snippets.

@dmitryrck
Created May 30, 2012 17:57
Show Gist options
  • Save dmitryrck/2837959 to your computer and use it in GitHub Desktop.
Save dmitryrck/2837959 to your computer and use it in GitHub Desktop.
class User < ActiveRecord::Base
has_many :things
end
class Thing < ActiveRecord::Base
validates :field_id, :uniqueness => { :scope => :user_id }
end
# Se vc for salvar um `user` com DENTRO DE UM NESTED FORM usando `things` ele vai gerar "falso positivo", ex.:
#
# things = { :user_id => 1, :other => true }
# things = { :user_id => 1, :other => false }
#
# Dentro de um nested gera falso positivo, pq antes de salvar o AR faz uma query para verificar,
# e depois salva todo de uma vez
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment