title: Creating record that belongs to 2 seperate tables
body: <p>So I am trying to create a record that is associated with 2 tables but I cannot seem to get it to work. </p>
  
  <blockquote>
    <p>Parameters: {"name"=>"asdfasd", "upc"=>"243252353", "availableOn"=>"07/12/2020", "properties"=>[{"name"=>"material", "value"=>"jean"}], "send_datum"=>{"name"=>"asdfasd", "upc"=>"243252353", "availableOn"=>"07/12/2020", "properties"=>[{"name"=>"material", "value"=>"jean"}]}}</p>
  </blockquote>
  
  <pre><code>class SendDataController &lt; ApplicationController
      protect_from_forgery with: :null_session
  
      def save
          product = Product.create(name:params[:name], upc:params[:upc].to_i, available_on:params[:availableon])
  
          x=0
          while x &lt; params[:properties].length
              property = product.properties.create(name:params[:properties][x][:name])
              property.product_properties.create(value:params[:properties][x][:value])
  
              x += 1;
          end
  
      end    
  end
  </code></pre>
  
  <p>This line is the one I cannot seam to get to work:</p>
  
  <blockquote>
    <p>property.product_properties.create(value:params[:properties][x][:value])</p>
  </blockquote>
  
  <p>This is my first react on rails project and understanding table assoc. has been a real challenge but I am getting there.  </p>
  
  <p>Models:</p>
  
  <pre><code>class Property &lt; ApplicationRecord
    belongs_to :product
    has_many :product_properties
  end
  
  class Product &lt; ApplicationRecord
    has_many :properties
    has_many :product_properties
  end
  
  class ProductProperty &lt; ApplicationRecord
    belongs_to :property
    belongs_to :product
  end
  </code></pre>
  
  <p>Migration:</p>
  
  <pre><code>class CreateProducts &lt; ActiveRecord::Migration[5.2]
    def change
      create_table :products do |t|
        t.string :name
        t.string :upc
        t.datetime :available_on
  
        t.timestamps
      end
    end
  end
  
  class CreateProperties &lt; ActiveRecord::Migration[5.2]
    def change
      create_table :properties do |t|
        t.string :name
  
        t.timestamps
      end
    end
  end
  
  class CreateProductProperties &lt; ActiveRecord::Migration[5.2]
    def change
      create_table :product_properties do |t|
        t.string :value
  
        t.timestamps
      end
    end
  end
  
  class AddProductRefToProperties &lt; ActiveRecord::Migration[5.2]
    def change
      add_reference :properties, :product, foreign_key: true
    end
  end
  
  class AddProductRefToProductProperties &lt; ActiveRecord::Migration[5.2]
    def change
      add_reference :product_properties, :product, foreign_key: true
    end
  end
  
  class AddPropertiesRefToProductProperties &lt; ActiveRecord::Migration[5.2]
    def change
      add_reference :product_properties, :property, foreign_key: true
    end
  end
  </code></pre>
  
  <p>Schema:</p>
  
  <pre><code>ActiveRecord::Schema.define(version: 2018_09_24_163027) do
  
    create_table "product_properties", force: :cascade do |t|
      t.string "value"
      t.datetime "created_at", null: false
      t.datetime "updated_at", null: false
      t.integer "product_id"
      t.integer "property_id"
      t.index ["product_id"], name: "index_product_properties_on_product_id"
      t.index ["property_id"], name: "index_product_properties_on_property_id"
    end
  
    create_table "products", force: :cascade do |t|
      t.string "name"
      t.string "upc"
      t.datetime "available_on"
      t.datetime "created_at", null: false
      t.datetime "updated_at", null: false
    end
  
    create_table "properties", force: :cascade do |t|
      t.string "name"
      t.datetime "created_at", null: false
      t.datetime "updated_at", null: false
      t.integer "product_id"
      t.index ["product_id"], name: "index_properties_on_product_id"
    end
  
  end
  </code></pre>
  
  <p><strong>UPDATE::</strong><br>
  It is related to the fact that the product_property is getting the property_id from property but is not getting the product_id from the product.  How do I fix that?</p>
  
  <p>Any help is greatly appreciated.  Thanks!!</p>