title: Laravel relationship belongsToMany with composite primary keys
body: <p>I have 3 tables and I'm trying to make relations between order_products and order_products_status_names. I have transition/pivot table named order_product_statuses. The problem are my PK, becuase I have in table orders 3 Pk, and I don't know how to connect this 3 tables throught relationships.
  My migrations are:</p>
  
  <p>Table Order Products:</p>
  
  <pre><code> public function up()
  {
      Schema::create('order_products', function (Blueprint $table) {
          $table-&gt;integer('order_id')-&gt;unsigned();
          $table-&gt;integer('product_id')-&gt;unsigned();
          $table-&gt;integer('ordinal')-&gt;unsigned();
          $table-&gt;integer('size');
  
          $table-&gt;primary(['order_id', 'product_id', 'ordinal']);
          $table-&gt;foreign('order_id')-&gt;references('id')-&gt;on('orders');
          $table-&gt;foreign('product_id')-&gt;references('id')-&gt;on('products');
      });
  }
  </code></pre>
  
  <p>Table Order Product Statuses  - this is my transition/pivot table between order_products and order_product_status_names</p>
  
  <pre><code> public function up()
  {
      Schema::create('order_product_statuses', function (Blueprint $table) {
          $table-&gt;integer('order_id')-&gt;unsigned();
          $table-&gt;integer('product_id')-&gt;unsigned();
          $table-&gt;integer('status_id')-&gt;unsigned();
          $table-&gt;integer('ordinal')-&gt;unsigned();
          $table-&gt;dateTime('created_at')-&gt;default(DB::raw('CURRENT_TIMESTAMP'));
  
          $table-&gt;foreign('order_id')-&gt;references('id')-&gt;on('orders');
          $table-&gt;foreign('status_id')-&gt;references('id')-&gt;on('order_product_status_names');
          $table-&gt;primary(['order_id', 'product_id', 'ordinal']);
      });
  }
  </code></pre>
  
  <p>And the last one is Order Product Status Names</p>
  
  <pre><code>public function up()
  {
      Schema::create('order_product_status_names', function (Blueprint $table) {
          $table-&gt;integer('id')-&gt;unsigned();
          $table-&gt;string('name');
          $table-&gt;string('code');
          $table-&gt;dateTime('created_at')-&gt;default(DB::raw('CURRENT_TIMESTAMP'));
  
          $table-&gt;primary('id');
      });
  }
  </code></pre>
  
  <p>I know that here is relationship blengsToMany in two ways, but I don't know or can I declarate this relation ( from order_products to order_product_status_names and inverse )? </p>