A
A
Alexander Rudomanov2015-04-03 08:22:44
MySQL
Alexander Rudomanov, 2015-04-03 08:22:44

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

You need to display the values ​​of the inbox and object tables (object.name | inbox.sms) available to a specific user from the user table. View rights are set in the objects_user table.
I understand how to link any 2 tables out of 4, but I can’t figure out how to link it all together. Drink please. Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ilyas Galiev, 2015-04-03
@MrGaliev

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.

V
vyachin, 2015-04-08
@vyachin

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 question

Ask a Question

731 491 924 answers to any question