Answer the question
In order to leave comments, you need to log in
How to build relationships?
there is a relationship between the tables
return $this->hasManyThrough(
Catalog_generation::class,
Catalog_generation_body::class,
'catalog_body_id',
'id',
'id',
'catalog_generation_id'
)->select([
"catalog_generations.id",
"catalog_generations.catalog_model_id",
"catalog_generation_bodies.catalog_body_id",
])
->with(['model.brand']);
Answer the question
In order to leave comments, you need to log in
Author, it's really hard to understand what you have in mind. But I would change the names. Models are named as ModelModel. Tables for models model_models. Otherwise it's easy to get confused. Especially with hasManyThrough. Also relations separately, DB queries based on relations - separately. relations can be useful to you in other queries. As for the relationship, you can try this (if I'm not confused)
return $this->hasManyThrough(
Catalog_generation::class,
Catalog_generation_body::class,
'current_model_id', //Внеший ключ текущей модели в Catalog_generation_body
'catalog_generation_body_id', // Внешний в Catalog_generation
'id' // Локальнй в текущей модели
)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question