S
S
Sergey Beloventsev2016-12-03 17:43:17
Yii
Sergey Beloventsev, 2016-12-03 17:43:17

What is wrong with links?

In fact, there are two links

public function getPillowcases(){
            return $this->hasOne(Gods::className(),['id'=>'idpillowcases']);
        }
    
        public function getDuvetcover(){
            return $this->hasOne(Gods::className(),['id'=>'duvetcover']);
        }

this is how I run both.
var_dump($model->pillowcases);
    var_dump($model->duvetcover);

only in the first case I get the object, and in the second it's just idwhy and where I could go wrong.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2016-12-03
@Sergalas

Name the relationship differently, the getter first looks for the property in the virtual properties of the record asset, and then in the relationships. You have the duvetcover property and the getter for the connection is the same.
Or don't use a getter when selecting related data:
$model->getDuvetcover()->one();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question