dimanche 18 mars 2018

Laravel Nesting relationship returns null

I have next db structure:

enter image description here

And I have next code in my Eloquent models:

Sample.php

public function polfzms()
{
    return $this->belongsToMany('App\Polfzm');
}

Polfzm.php

public function samples()
{
    return $this->belongsToMany('App\Sample');
}

public function gene()
{
    return $this->belongsTo('App\Gene');
}

Gene.php

public function polfzms()
{
    return $this->hasMany('App\Polfzm');
}

I try to get sample data with his labels, polfzms and gene using dot in where clause - polfzms.gene

public function show($id)
{
    return Sample::with('labels', 'polfzms.gene')->findOrFail($id);
}

But I have got a "gene":null

{
   "id":18,
   "person_id":1,
   "prefix_id":3,
   "labels":[
      {
         "id":1,
         "name":"Name1",
         "meaning":"dfdf",
         "pivot":{
            "sample_id":18,
            "label_id":1
         }
      },
   ],
   "polfzms":[
      {
         "id":1,
         "name":"G20210",
         "id_gene":1,
         "pivot":{
            "sample_id":18,
            "polfzm_id":1
         },
         "gene":null
      }
   ]
}

I use latest laravel version. How can I fix it?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2FRAF55
via IFTTT

Aucun commentaire:

Enregistrer un commentaire