S
S
Sergey Beloventsev2021-10-13 15:09:33
Yii
Sergey Beloventsev, 2021-10-13 15:09:33

How to make a hasMany query with a cast?

Tell me who knows how to make a hasMany binding with a ghost of types, I do this

public function getProjectAddress()
    {
        return $this->hasMany(ProjectAddress::class, ['project_id' => 'id']);
    }

    public function getAddress()
    {
        return $this->hasMany(Address::class, ['id' => 'address_id'])->via('projectAddress');
    }
   public function getRegion(): ActiveQuery
    {
        return $this->hasMany(RegionService::getRegionClassName(), ['fias_id' => new Expression('fias_id::text')])->via('address');

    }


then model-> region gives an error Getting unknown property: Address::fias_id::text and gives
Model::find()->joinWish('region')
LEFT OUTER JOIN "region" ON "address". = "region"."fias_id"

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vitaly_74, 2021-10-16
@vitaly_74

what do you mean by type casting, and what do you want to see at the end of this action?
at this moment. as far as I understand, it does not find a connection in the address table

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question