class Phone < ActiveRecord::Base belongs_to :contact validates :phone, uniqueness: { scope: :contact_id } end
ここの一意性のバリデーションの掛け方がtrueではなく
{ scope: :contact_id }となっていますが、これはどういう意味でしょうか?
いまいち分かりづらく質問させてもらいます。
phoneモデルのphoneカラムにダブりが出てはいけない、とまでは分かるのですが・・・
DB構成
create_table "contacts", force: true do |t| t.string "firstname" t.string "lastname" t.string "email" t.datetime "created_at" t.datetime "updated_at" end create_table "phones", force: true do |t| t.integer "contact_id" t.string "phone" t.string "phone_type" t.datetime "created_at" t.datetime "updated_at" end
class Phone < ActiveRecord::Base belongs_to :contact class Contact < ActiveRecord::Base has_many :phones
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/04/25 02:10
2017/04/25 08:13
2017/04/30 14:42