Difficulty In Porting Relation From Yii 1

I am having a trouble defining relation with order

In Yii 1 the relation is defined as such…

‘nameservers’ => array(self::MANY_MANY, ‘YHost’, ‘host_domain(domain_id, host_id)’, ‘order’=>‘nameservers_nameservers.is_master desc, nameservers_nameservers.host_domain_id’, ‘condition’=>“status=‘A’”)

host_domain is a pivot table and includes

domain_id (int), host_id (int), is_master (boolean), host_domain_id (int)

the main table is domains, with pk domain_id (int)

I can get everything except the order to work with a relation like…

$this->hasMany(‘YHost’,[‘host_id’=>‘host_id’])->viaTable(“host_domain”,[‘domain_id’=>‘domain_id’)->andWhere(“status=‘A’”)->all();

If I try to define the orderBy I get error that the table can’t be found because the final query is split into at least two queries…

Can anyone help me how to define this relation such as the orderBy can be used in a successful way?

This is because yii2 does not join relations by default anymore. to do so, you have to join manually: https://github.com/yiisoft/yii2/blob/master/docs/guide/active-record.md#joining-with-relations

thanks, but is it neccessary to get my original record again?, in my case I have the domain object and it differs how it’s used which mean I don’t want to join everything together always.

Maybe I should not use via and rather define the join myself?