我正在开发一个 Shopify 应用程序,我正在尝试在我的数据库中创建一个关系,其中我有一个 Shop 模型和一个 Address 模型,一个商店可以有不同的地址,每个地址都与一个商店相关。
所以我有这个:
模型/shop.rb
class Shop < ActiveRecord::Base
include ShopifyApp::SessionStorage
has_many :addresses
end
模型/地址.rb
class Address < ApplicationRecord
belongs_to :shop
end
db/migrate/create_shops.rb
class CreateShops < ActiveRecord::Migration[5.1]
has_many :addresses
def self.up
create_table :shops do |t|
t.string :shopify_domain, null: false
t.string :shopify_token, null: false
t.timestamps
end
add_index :shops, :shopify_domain, unique: true
end
def self.down
drop_table :shops
end
end
db/migrate/create_shops.rb
class CreateAddresses < ActiveRecord::Migration[5.1]
def change
create_table :addresses do |t|
t.text :Address1
t.text :Address2
t.string :Postal
t.string :Phone
t.string :City
t.timestamps
end
end
end
我想我没有这个好... 那么,我怎样才能将地址添加到我的数据库中的商店?
谢谢你。