Framework: Eloquent relationship method named "size" bug.

Created on 8 Oct 2016  路  2Comments  路  Source: laravel/framework

  • Laravel Version: 5.2.31
  • PHP Version: 7.0.10
  • Database Driver & Version: MariaDB 10.1.17-MariaDB-1~trusty

    Description:

Created a belongsTo relationship called size and it is returning null when called as property, however when calling as function, builder object is returned.

Steps To Reproduce:

class Product extends Eloquent {

  //

  function size() 
  {
     return $this->belongsTo(InventorySizes::class, 'inventory_size_id');
  }
}
$product->size // returns null
$product->size()->first() // returns Size Model as expected

Most helpful comment

Hey @jaketoolson, could it be because you have a column on the table with the same name as the property?

All 2 comments

Hey @jaketoolson, could it be because you have a column on the table with the same name as the property?

@seanmangar son of a... that was it 馃憤 I was going crazy too, checking everything, even my tests yielded the same "bug". Sigh those damn magic properties ;)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

PhiloNL picture PhiloNL  路  3Comments

Fuzzyma picture Fuzzyma  路  3Comments

CupOfTea696 picture CupOfTea696  路  3Comments

felixsanz picture felixsanz  路  3Comments

ghost picture ghost  路  3Comments