D
D
Dmitriy G2019-02-02 22:14:10
MySQL
Dmitriy G, 2019-02-02 22:14:10

How to correctly access the data of a linked table?

There is an Event table where several user ids from the Users table are recorded in one record
For example:
Journalist (id_j) - User 1,
Editor (id_red) - user 2,
Driver (id_driver) - User 3, Operator
(id_cam) - user 4
the users table
If I want : id_j.event = users.surname, id_red = user.surname etc
If only possible :
$event = Event::findone($id);
$event->users->surname;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitriy G, 2019-02-03
@Dimgol

So far, the issue has been resolved like this:
create a view in MySql

SELECT
  operators.username,
  journalist.username,
  driver.username
FROM event
  INNER JOIN user operators
    ON event.id_operator = operators.id
  INNER JOIN user journalist
    ON event.id_journalist = journalist.id
  INNER JOIN user driver
    ON event.id_driver = driver.id

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question