php - Laravel 5.2 EagerLoading relationship returns null -


i'm upgrading laravel 5.2 4.2 , running weird issues when i'm using eager loading on relationship, returns null, can call manually.

here's parent model:

namespace app\models\hours;  class hours extends model {  /**  * model setup  */ protected $table = 'leave_hours'; protected $primarykey = 'leave_id'; public $timestamps = false;  /**   * relationships */ public function hoursstatus() {     return $this->belongsto('app\models\hours\hoursstatustype', 'leave_status_code'); } 

here's hoursstatustype model:

<?php  namespace app\models\hours;  use illuminate\database\eloquent\model;  class hoursstatustype extends model {      /**      * model setup      */     protected $table = 'leave_status_type';     protected $primarykey = 'leave_status_code';     public $timestamps = false;      /**       * relationships     */     public function hours()     {         return $this->hasmany('app\models\hours\hours');     }  } 

basically hours has pto requests has status (ie. pending, approved, etc). hoursstatustype has 4 rows , belongs many of hours request.

i'm doing big request on hours like:

$requests = hours::with('hoursstatus')->get();  foreach($requests $r){    print_r($r->hoursstatus); } 

when try print out using foreach loop, hoursstatus relationship blank. however, when when call without eager loading, it's fine. thing have changed since upgrading 4.2 (besides adding namespace) change hoursstatus relationship belongsto hasone. couple of posts mentioned changing should fix it. not much.

am missing something? thanks!

you should add public $incrementing = false; models setup, when pk not autoincrementing int.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -