N
N
NetyNicka2016-11-03 14:43:03
Yii
NetyNicka, 2016-11-03 14:43:03

How to make hasMany relation from 2 tables in yii2?

There is a
texture (id, url) table,
as well as user_layer(id, texture_id) and object_layer(id, texture_id) tables.
There is a relationship in the Texture model:

public function getLayers()
    {
        return $this->hasMany(UserLayer::class, ['texture_id' => 'id']);
    }

But you need to make sure that the connection gets data from the UserLayer and ObjectLayer at the same time.
How to implement it correctly?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2016-11-03
@NetyNicka

as far as I understand you need eager loading

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question