私はUserモデルとShopモデルを持っています。私は1つのショップしか作成できないようにしたい。だから私のUserモデルhas_one associationは複数のレコードをレールに作成します
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
validates :terms_and_conditions, :acceptance => true
has_one :shop
end
そして、私の店のモデルに私はすでに1店を持つユーザーのための新しいお店を作成しようとすると、エラーがないこの
class Shop < ApplicationRecord
has_many :products, dependent: :destroy
belongs_to :user
end
のように見えますが、コンソールから正常にコミットします。
[
#<Shop id: 1, name: "Rabin & Rose Shop", location: "Banepa Kavre Nepal", description: "oho k vhk kl;o jjio ko;k; jljlkj", rating: nil, delivery_service: true, user_id: 1, created_at: "2017-09-27 15:31:57", updated_at: "2017-09-27 15:31:57", img_url: nil>,
#<Shop id: 2, name: "jhoney", location: "sins shop", description: "the entire fuck history here", rating: nil, delivery_service: true, user_id: 1, created_at: "2017-09-28 00:55:44", updated_at: "2017-09-28 00:55:44", img_url: nil>,
#<Shop id: 3, name: "Thakur Shop", location: "Pulbazar banepa", description: "Our shop has chicken bedroom. you can met call gir...", rating: nil, delivery_service: true, user_id: 2, created_at: "2017-09-28 01:50:40", updated_at: "2017-09-28 01:50:40", img_url: nil>,
#<Shop id: 4, name: nil, location: nil, description: nil, rating: nil, delivery_service: true, user_id: 1, created_at: "2017-09-28 03:49:34", updated_at: "2017-09-28 03:49:34", img_url: nil>
]
user_id = 1
には複数のレコードがあります。