Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
一意性検証を持つすべての属性のリストを返すことができるかどうか疑問に思っていますか? たとえば、私はモデル Person を持っています。一意性制約を持つ「Person」の属性のリストを返したいと思います。何か案は?
次のようなことができます
Person.validators.select { |v| v.is_a?(ActiveRecord::Validations::UniquenessValidator) }
Person モデルの一意性バリデータのリストを取得します。各バリデーターには@attributesインスタンス変数があり、それがおそらく必要なものです。
@attributes