How to display records from DB for a specific user (s)?

Hi all, how to show records for a particular user, for example in the database in table 1, the data is stored with the content, and the second table data is stored with the user IDs that have access. Communication - many-to-many
Table 1
5cf8268a9ac9c996126286.png

Table No. 2
5cf826ba172d8087768246.png

Sample code
$model = Object::find()->with('access')->all();
March 23rd 20 at 19:17
2 answers
March 23rd 20 at 19:19
Solution
What prevents you to perform 2 queries?
1) to Get the array instance_id from table 2 for the specified user.
2) Make a selection of records from table 1 according to the known id
Good answer, thank you, is somehow possible to implement it means Yii2 through ViaTable. - marian_Emard commented on March 23rd 20 at 19:22
@marian_Emard, ok google: yii2 hasMany relation

5cf8808644774141675675.jpeg - Bridgette.Gerhold commented on March 23rd 20 at 19:25
Why two request when it is solved one?
The solution is so-so...
Pay attention to the answer @marjory.Willhe closer to the truth. - jessika commented on March 23rd 20 at 19:28
March 23rd 20 at 19:21
Solution
Not quite clear is the question. You've already written communiques in the model?
If not - create it in the model for table 1 (the relation linking it to table 2) and use.
Example :
// let's have the posts and the authors, by the relation
$posts = Post::find()
 ->joinWith('author') // this report
 ->where(['like', 'author.name', $searchword]) // this condition communiques
 ->all();

Find more questions by tags Yii