Answer the question
In order to leave comments, you need to log in
Why doesn't an unsaved model see relays in Yii2?
I have one pre-ordered parameter (by which the relay is connected), the connection is not by id.
That is, I create a new instance, and set a certain parameter in init
$productEntity = ProductEntity::find()->where(['alias' => $this->productName()])->one();
public function getParamList()
{
return $this->hasMany(ProductAttribute::className(), ['product_entity_id' => 'id'])
->where(['product_entity_id' => $this->product_entity_id]);
}
Answer the question
In order to leave comments, you need to log in
when you create a model, your model is virtual and is not tied to the base in any way.
There are a couple of solutions that come to mind:
$mode->save(); /*code*/ $model->delete();
and the second way, make a getter
protected $_rel;
public function getRel() {
if ($this->$_rel) return $this->$rel;
else {
$model = Model::findAllByAttributes();
if (!$model) return false;
$this->_rel = $model
return $this->_rel;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question