Fake a composite primary key? Rails

后端 未结 3 1435
刺人心
刺人心 2021-02-09 15:59

I have a table with id|patient_id|client_id|active. A record is unique by patient_id, client_id meaning there should only be one enrollment per patient per client. Normally I wo

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-09 16:31

    Validations would work (Back them up with a unique index!), but there's no way to get a true composite primary key in vanilla Rails. If you want a real composite primary key, you're going to need a gem/plugin - composite_primary_keys is the one I found, but I'm sure there are others.

    Hope this helps!

提交回复
热议问题