title: Rails how to create relationships between models
body: <p>I'm developing a Shopify App and I'm trying to create a relationship in my database where I have a Shop model and an Address model, and one shop can have different addresses and every address is related to one shop.</p>
  
  <p>So I have this:</p>
  
  <p><strong>models/shop.rb</strong></p>
  
  <pre><code>class Shop &lt; ActiveRecord::Base
    include ShopifyApp::SessionStorage
    has_many :addresses
  end
  </code></pre>
  
  <p><strong>models/address.rb</strong></p>
  
  <pre><code>class Address &lt; ApplicationRecord
      belongs_to :shop
  end
  </code></pre>
  
  <p><strong>db/migrate/create_shops.rb</strong></p>
  
  <pre><code>class CreateShops &lt; 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
  </code></pre>
  
  <p><strong>db/migrate/create_shops.rb</strong></p>
  
  <pre><code>class CreateAddresses &lt; 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
  </code></pre>
  
  <p>I think I don't have this well...
  <strong>So, how can I add addresses to a shop in my database?</strong> </p>
  
  <p>Thank you. </p>