title: Accessing Eloquent relationship attributes
body: <p>I have three models all related by one-to-many. Category, Subcategory and Style. I have relationships working both ways - though I seem to have a problem accessing related attributes. </p>
  
  <p>After my queries have ran, I'm left with this an instance of Style where 'relations' is an instance of Subcategory, and 'relations' in Subcategory is an instance of Category. Which is all correct.</p>
  
  <p>The problem is that I now seem to not be able to access the related model instances. For example, if I call:</p>
  
  <pre><code>$style-&gt;subcategory-&gt;name;
  </code></pre>
  
  <p>I get 'Trying to get property of non-object'. So I tried calling just $style->subcategory and the result is '1'.</p>
  
  <p>Why doesn't $style->subcategory return the instance of the subcategory model? Am I missing something or is my understanding incorrect?</p>
  
  <p><strong>--EDIT--</strong></p>
  
  <p><strong>Models</strong></p>
  
  <p>Category </p>
  
  <pre><code>&lt;?php
  
  namespace Paragon\Products;
  
  use Illuminate\Database\Eloquent\Model as Eloquent;
  
  class Category extends Eloquent {
  
      protected $table = 'product_categories';
  
      protected $fillable = [
              'name',
              'slug',
              'image'
      ];
  
      public function subcategories() {
              return $this-&gt;hasMany('Paragon\Products\Subcategory', 'category');
      }
  
  }
  </code></pre>
  
  <p>Subcategory                           </p>
  
  <pre><code>&lt;?php
  
  namespace Paragon\Products;
  
  use Illuminate\Database\Eloquent\Model as Eloquent;
  
  class Subcategory extends Eloquent {
  
      protected $table = 'product_subcategories';
  
      protected $fillable = [
              'category',
              'name',
              'slug',
              'image'
      ];
  
      public function styles() {
              return $this-&gt;hasMany('Paragon\Products\Style', 'subcategory');
      }
  
      public function category() {
              return $this-&gt;belongsTo('Paragon\Products\Category', 'category');
      }
  
  }
  </code></pre>
  
  <p>Style</p>
  
  <pre><code>&lt;?php
  
  namespace Paragon\Products;
  
  use Illuminate\Database\Eloquent\Model as Eloquent;
  
  class Style extends Eloquent {
  
      protected $table = 'product_styles';
  
      protected $fillable = [
              'subcategory',
              'name',
              'slug',
              'image'
      ];
  
      public function subcategory() {
              return $this-&gt;belongsTo('Paragon\Products\Subcategory', 'subcategory');
      }
  
  }
  </code></pre>
  
  <p><strong>Query</strong></p>
  
  <pre><code>$style-&gt;where($id, $item)-&gt;with('subcategory.category')-&gt;first();
  </code></pre>
  
  <p><strong>Tables</strong></p>
  
  <p>Paragon\Products\Category</p>
  
  <pre><code>ID    ...
  1
  2
  </code></pre>
  
  <p>Paragon\Products\Subcategory</p>
  
  <pre><code>ID   Category    ...
  1    2
  2    2
  </code></pre>
  
  <p>Paragon\Products\Style</p>
  
  <pre><code>ID   Subcategory    ...
  1    1
  2    1
  </code></pre>
  
  <p>Since the subcategory method in the Style model should refer to a single instance of Subcategory and not a Collection of them, shouldn't I be able to just call attributes the way I am (or am trying to)?</p>