Why is the translations relationship different on Stack Overflow? Didn't you copy the lines from your codebase?
Jul 13, 2018
4
Level 8
Relationship in Laravel-5.6
I have three tables like below.
posts
_id - integer
name - string
sentences
_id - integer
post_id - integer
name - string
translations (word by word)
_id - integer
post_id - integer
sentence_id - integer
word_id - integer
name - string
In PostController.php I am trying to fetch data like below
return Post::with(['sentences', 'sentences.translations'])->limit(2)->get();
I have function in post.php model is like below
protected $primaryKey = '_id';
public function sentences()
{
return $this->hasMany('App\Model\sentence', 'post_id','_id');
}
I have function in sentences.php model is like below
protected $primaryKey = '_id';
public function translations()
{
return $this->hasMany('App\Model\translation', 'sentence_id','_id');
}
I would like to fetch posts along with sentences and translations.
I can fetch post and sentences but I am facing issue while I am trying to fetch translations.
I am getting below error
"SQLSTATE[42S22]: Column not found: 1054 Unknown column 'translations.sentence_id_id' in 'where clause' (SQL: select * from `translations` where `translations`.`sentence_id_id` in (1, 2
Please or to participate in this conversation.