Question about relations and magic getters

I have a model (Offer) which has a relation getContactPeople().

When I access the relation…

$offer = Offer::find($offerId);
var_dump($offer->contactPeople);
var_dump($offer->getContactPeople());

the output from the (magic getter) property is an array, while the method is still an ActiveQuery. I expected them to be equal.

Is there something in the docs about the rationale behind this behavior?


Additional question: How could I order contact people by a rank in the ContactPeople model?

yes, https://www.yiiframework.com/doc/guide/2.0/en/db-active-record#accessing-relational-data

not sure what you mean with that? Something like this?

var_dump($offer->getContactPeople()->orderBy(['rank' => SORT_ASC])->all());
1 Like