This is a belongsToMany relationship with a_b as pivot table, not a hasManyThrough (which chains two hasMany).
About many to many relationship
Now I have a pretty standard many to many relationship by establishing 3 tables:
table a: id, value
table b: id, value
table a_b: a_id, b_id
now when i want to access table b by table a, i have a class like this:
class a extends Model { protected $table = 'a'; public function b() { return $this->hasManyThrough('a','a_b', 'a_id','id'); } }
and i get an error message of such when i call a::find(1)->b in php:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'a_b.id' in 'on clause' (SQL: select b.*, a_b.a_id from b inner join a_b on a_b.id = a.id where a.id = 25)
pretty obvious the problem is a_b.id is not editable from model definition. is it really the case? what can i do if im not possible to change the database?
Please or to participate in this conversation.