title: Updating timestamps on attaching/detaching Eloquent relations
body: <p>I'm using Laravel 4, and have 2 models:</p>
  
  <pre><code>class Asset extends \Eloquent {
      public function products() {
          return $this-&gt;belongsToMany('Product');
      }
  }
  
  class Product extends \Eloquent {
      public function assets() {
          return $this-&gt;belongsToMany('Asset');
      }
  }
  </code></pre>
  
  <p><code>Product</code> has the standard timestamps on it (<code>created_at</code>, <code>updated_at</code>) and I'd like to update the <code>updated_at</code> field of the <code>Product</code> when I attach/detach an <code>Asset</code>.</p>
  
  <p>I tried this on the <code>Asset</code> model:</p>
  
  <pre><code>class Asset extends \Eloquent {
      public function products() {
          return $this-&gt;belongsToMany('Product')-&gt;withTimestamps();
      }
  }
  </code></pre>
  
  <p>...but that did nothing at all (apparently). <strong>Edit</strong>: apparently this is for updating timestamps on the pivot table, not for updating them on the relation's own table (ie. updates <code>assets_products.updated_at</code>, not <code>products.updated_at</code>).</p>
  
  <p>I then tried this on the <code>Asset</code> model:</p>
  
  <pre><code>class Asset extends \Eloquent {
      protected $touches = [ 'products' ];
  
      public function products() {
          return $this-&gt;belongsToMany('Product');
      }
  }
  </code></pre>
  
  <p>...which works, but then breaks my seed which calls <code>Asset::create([ ... ]);</code> because apparently Laravel tries to call <code>-&gt;touchOwners()</code> on the relation without checking if it's <code>null</code>:</p>
  
  <blockquote>
    <p>PHP Fatal error:  Call to undefined method Illuminate\Database\Eloquent\Collection::touchOwners() in /projectdir/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php on line 1583</p>
  </blockquote>
  
  <p>The code I'm using to add/remove <code>Asset</code>s is this:</p>
  
  <pre><code>Product::find( $validId )-&gt;assets()-&gt;attach( $anotherValidId );
  Product::find( $validId )-&gt;assets()-&gt;detach( $anotherValidId );
  </code></pre>
  
  <p>Where am I going wrong?</p>