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

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -