我有3款車型:Item,Serials和SerialsCategories。當我顯示Item窗體(創建或更新)時,我需要顯示屬於上一步中選定的categoryId的連續劇。一個序列可以屬於多個類別。Yii2。相關車型
現在,我有我的產品型號:
public function getSerialsTypeByCategory() {
return (new SerialType)->getByCategory($this->itemCategoryId);
}
在我SerialType型號:
public function getByCategory($itemCategoryId) {
return SerialTypeItemCategory::find()->select(['serialTypeId'])->where(['itemCategoryId' => $itemCategoryId])->all();
}
這是工作,它做什麼,我需要,但...這是正確的方式?有沒有更好的辦法?
看來我的權利..代碼是在正確的地方(模型),並寫在正確的方式(吸氣) – scaisEdge