laravel 5 - Eloquent/Laravel5 linking distant relations ("hasOneThrough") -


the question in short:

"pages" , "tasks" have many-to-many relationship linked pivot table "page_tasks". table "responses" linked pivot table foreign key "page_task_id".

now want able access page , task response belongs directly eloquent. hasmanythrough function not work, exspects foreign_keys @ different places:

 public function task(){     return $this->hasmanythrough('pagetask', 'task', 'page_task_id', 'task_id'); } 

unknown column 'tasks.page_task_id' in 'field list'

this means eloquent exspects task table having foreign key page_task_id pointing page_tasks. in model page_tasks table has foreign key task_id pointing tasks. how tell eloquent fact?

an other approach tried use existing relations defined:

public function task(){     return $this->page_task->task(); } 

this tells me there no methoid called "task".

what recommended way achieve this? doing wrong?




here more details if needed:

"pages" , "tasks" have many-to-many relationship pivot table page_tasks linking it.

page-model:

class page extends model {     public function tasks(){         return $this->belongstomany('task', 'page_tasks');     } } 

task-model:

class task extends model {     public function pages()     {         return $this->belongstomany('page', 'page_tasks');     } } 

this works fine.

response-model looks this

class response extends model {     protected $fillable = [         'page_task_id',     ];      public function page_task(){         return $this->belongsto('app\pagetask', 'page_tasks');     }      public function task(){          ??????     } } 

pagetask-model looks this:

class pagetask extends model {     protected $fillable = [         'page_id',         'task_id',      ];     public function page(){         return $this->belongsto('page');     }     public function task(){         return $this->belongsto('task');     }     public function responses(){         return $this->hasmany('response');     } } 


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -