K
K
kakero2018-05-21 12:46:19
Laravel
kakero, 2018-05-21 12:46:19

How to make deep HasManyThrough in laravel?

Good day!
I created a relation like this:
Тип.Город.Улица.Дом.Квартира
In this respect, the apartment should depend on the House and on the Type at the same time - you need to get something like this request:

select * from `apartments` where `apartments`.`home_id` in ('1', '2', '3') and `type_id` = '777'

The problem is that the HasManyThrough relation only looks at a couple of levels and it is impossible to reach the very first model with it.
Tell me how can this be done?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Aksentiev, 2018-05-21
@Sanasol

You have a strange request.
Select just a subquery with an indication of the type, if necessary.
Links go along the chain, they are not non-accumulative.
Only if the values ​​of all tables are unique (there are created for each bundle), then at the end there would be an apartment that belongs to the original type.
And if it's just dictionaries, then of course it won't work that way.
With regular hasOne relationships, nesting is not limited in any way.
And you can do it like this:
client.address.city.regionsCity.region

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question