I
I
idaho2017-09-15 10:10:57
Yii
idaho, 2017-09-15 10:10:57

YII2 how to select by values ​​in fields?

Hello
There is a need to select data with the same field values ​​from the database
like:

SELECT * FROM `pedigrees` WHERE `sire`=733 AND `dam`=731

In the model:
public function getSiblings(){
             $sibling = Pedigrees::find()
            ->where(['sire' => 'sire', 'dam' => 'dam'])
            ->all();
        return $sibling;

How to pass field content data to a request?
for the request to be->where(['sire' => '733', 'dam' => '731'])

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
idaho, 2017-09-18
@idaho

Did it like this:

public function getSiblings(){
            $sire = Pedigrees::find()->where(['LIKE', 'sire', $this->sire])->all();
            $dam = Pedigrees::find()->where(['LIKE', 'dam', $this->dam])->all();
             $sibling = Pedigrees::find()
            ->where(['sire' => $sire, 'dam' => $dam])
            ->all();
        return $sibling;

S
Sergey Suntsev, 2017-09-15
@GreyCrew

public function getSiblings($sire, $dam){
             $sibling = Pedigrees::find()
            ->where(['sire' => $sire, 'dam' => $dam])
            ->all();
        return $sibling;

So it doesn't work?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question