ruby on rails - How to limit one value to appear at most once in a column in Postgresql? -
how add constraint or unique index position
column in staff entity value master
can appear @ once while other values can appear many times?
is possible?
i using postgres database, ruby on rails , schema.rb
.
i'm not sure postgres enforces kind of constraint. alternative solution set custom validation on model along lines of
class somemodel validate :one_master_permitted private def one_master_permitted errors.add(:position, "some error message") if somemodel.find_by(position: "master") end end
Comments
Post a Comment