D
D
ddddd tttt2019-03-09 02:38:00
Yii
ddddd tttt, 2019-03-09 02:38:00

How to remove fields which are not in select() from ActiveRecord result?

/**
     * @return ActiveQuery
     */
    public function getUser(): ActiveQuery
    {
        return $this->hasOne(Customer::class,['id' => 'customer_id'])->select(['id', 'rating_consumer']);
    }
Часть fields()
'user' => function () {
                return $this->user;
  },

How can I make sure that only the selected fields are returned, and the rest with null are not returned?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
padlyuck, 2019-03-09
@padlyuck

->asArray()but then you get an array, not an object. no other way.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question