S
S
Sergey Beloventsev2018-04-26 16:20:59
Yii
Sergey Beloventsev, 2018-04-26 16:20:59

Using stubs for activeQuery queries?

how can i fix this code

$book = $this->getBookingOptions()->indexBy('session')->all();

public function getBookingOptions()
{
    return $this->hasMany(BookingOption::className(), ['booking_id' => 'id']);
}

doing so
$this->bookingCount=Stub::make($this->bookingCount,['getBookingOptions'=>new BookingOption]);

get
[yii\base\UnknownMethodException] Calling unknown method: app\models\BookingOption::indexBy

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Egor Mokeev, 2018-05-03
@zetamen

You didn’t even get into the method signature, smoke the dock
. I guess something like

$booking = Stub::make('Booking', [
    'getBookingOptions' => function () { return [new BookingOption()]; }
]);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question