E
E
EVOSandru62017-09-14 20:10:15
Yii
EVOSandru6, 2017-09-14 20:10:15

How to select only those models in Yii2 that have more than zero hasMany elements in the relationship?

Good afternoon,
There is a Users
model , it has a connection:

public function getVideos()
    {
        return $this->owner->hasMany($this->className, [$this->attribute => 'id']);
    }

How to pull out Users models only those with at least one video attached?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2017-09-14
@slo_nik

Good evening.
Something like this

public function getVideos()
    {
        return $this->owner->hasMany($this->className, [$this->attribute => 'id'])->where([/* тут Ваше условие */]);
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question