Ruby on Rails Friday, September 11, 2015

On 11 September 2015 at 16:43, Luis <luismcdougall@gmail.com> wrote:
> 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.

Show us the code are you using to save it.

Colin

--
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+unsubscribe@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/CAL%3D0gLuiDna0VjqVv9OVhMnnZKEZUenhsdUmCbD68kcaXiTTqw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment