title: Laravel one-to-many relationship - a reference to a non-existent field
body: <p>What do I forget about doing migrations in Lavarel that once relations act to me like this and once so? Presenting what I want to get is I want to assign the user his order and order the products he ordered. So I have a User table, the Order table, and the OrderProduct table. Usera table with one-to-many relation with the Order table, Order table with one-to-many relation with the OrderProduct table. Starting from the relation Order and OrderProduct, I get an error:</p>
  
  <pre><code>SQLSTATE[42S22]: Column not found: 1054 Unknown column 'order_products_tables.order_table_id' in 'where clause' (SQL: select * from `order_products_tables` where `order_products_tables`.`order_table_id` = 1 and `order_products_tables`.`order_table_id` is not null)
  </code></pre>
  
  <p>And this error says clearly and clearly that he can not find the order_table_id column in the order_products_tables table and I am not surprised what it may sound silly because there is no such field but there is an order_id field and in migrations is described with which field is the relationship and I can not understand why Laravel tries refer to order_products_tables.</p>
  
  <p>Migrations Order:</p>
  
  <pre><code>Schema::create('order_tables', function (Blueprint $table) {
      $table-&gt;increments('id');
  
      $table-&gt;integer('user_id')-&gt;unsigned()-&gt;nullable();
  
      $table-&gt;foreign('user_id')
          -&gt;references('id')
          -&gt;on('users');
  
      $table-&gt;timestamps();
  });
  </code></pre>
  
  <p>Migrations OrderProduct:</p>
  
  <pre><code>Schema::create('order_products_tables', function (Blueprint $table) {
      $table-&gt;increments('id');
  
      $table-&gt;integer('order_id')-&gt;unsigned();
  
      $table-&gt;integer('count')-&gt;unsigned();
      $table-&gt;integer('price')-&gt;unsigned();
  
      $table-&gt;foreign('order_id')
          -&gt;references('id')
          -&gt;on('order_tables');
  
      $table-&gt;timestamps();
  });
  </code></pre>
  
  <p>As it results from the migration, the order_products_tables table stores the record ID from the order_tables table and the relationship is based on that ID.</p>
  
  <p>Model Order table:</p>
  
  <pre><code>class OrderTable extends Model
  {
      protected $table = 'order_tables';
  
      public function user()
      {
          return $this-&gt;belongsTo(User::class, 'id');
      }
  
      public function products()
      {
          return $this-&gt;hasMany('App\OrderProductTable');
      }
  }
  </code></pre>
  
  <p>Model OrderProduct table:</p>
  
  <pre><code>class OrderProductTable extends Model
  {
      protected $table = 'order_products_tables';
  
      public function order()
      {
          return $this-&gt;belongsTo(OrderTable::class, 'id');
      }
  }
  </code></pre>
  
  <p>I do not understand why the reference to order_table_id is going. I have done other relations, eg User and Order on the same principle, and it works without a problem, suddenly here I have such a case. Where should I look for a solution and why does it wo</p>