Answer the question
In order to leave comments, you need to log in
Complex structure of database and yii2?
Completely confused, you need a kick in the right direction. There is no way to change and simplify the database.
Essence:
4 tables in the database:
object: id | name | number
inbox : id | number | sms
user: id | name
objects_user: id_object | id_user
object.number = inbox.number
object.id = objects_user.id_object
user.id = objects_user.id_user
Answer the question
In order to leave comments, you need to log in
As an option:
1. Collect id of objects with current user_id from objects_user
2. Get objects. WHERE IN(1,2,3)
3. Get data from inbox and, say, collect it into an array number => [inbox, inbox...]
4. Display.
Maybe there are better options, but that's how I would do it.
Can be solved with one sql query (the last join can be omitted if the data from the user table in the selection is not needed)
select object.name, inbox.sms from object
inner join inbox on inbox.number = object.number
inner join objects_user on objects_user.id_object = object.id
inner join user on user.id = objects_user.id_user
where user.id = :id_user
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question