Hi!

I have the following classes  for  postgres rails 4 project :

class Medhospital < ActiveRecord::Base
  belongs_to :pcp
  belongs_to :hospital
  validates_uniqueness_of :pcp_id, :scope => :hospital_id 
end

class Pcp < ActiveRecord::Base
    has_many :scheds
    has_many :medhospitals, dependent: :destroy 
    has_many :hospitals, through: :medhospitals
    has_many :patients, through: :scheds
    accepts_nested_attributes_for :medhospitals, reject_if: :all_blank, 
allow_destroy: true
end

class Hospital < ActiveRecord::Base
    has_many :scheds
    has_many :medhospitals
    has_many :pcps, through: :medhospitals
end

I am forcing the error to test and the validation for the uniqueness it is 
not working instead I get this exception:
PG::UniqueViolation - ERROR:  duplicate key value violates unique 
constraint "index_medhospitals_on_pcp_id_and_hospital_id"

BTW I am testing manually  from a view form.

Am I doing something wrong ? 

Thanks
-Luis

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/14eaf24c-48d8-486c-8e4f-b2f27ed9a112%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to