fillingRoute property question and working with more complex junction tables
phdcoder opened this issue · 9 comments
Thanks for the extension !! At first its working !!. But i have some questions. Its not clear how to use the fillingRoute property. I suppose that you need to put a route to an action that return the relational items that already belong to the master, so when you update the Master it already fills with the existent data. I made an action that return a list( id ) as an array , but it didn't work.
The other question is, how can i work with a junction table with more columns, i.e. an order junction table with quantities?
Sorry to post here. But i replied you topic on yii forum but got no return.
fillingRoute
is needed for auto filling editable attribute for given route(s).
Loading it everytime in afterFind
event handler is not good, because it's kind of eager loading regardless if you want it or not and separate query will be executed for every finded model.
Usually auto filling is needed only in one route - where you update model.
For getting this values in other routes it's better to use according relation.
As for second problem - it's planned in #1.
Thanks man ! its clear how to use now. I updated my code right now. Looking forward to the next version !!!
Sorry, can the example method of fillingRoute
is added to documentation too ?
Like for in this documentation in tests/default/update
method
What exactly do you mean? It's already mentioned in the docs with explaining comment.
sorry, I still do not understand what kind the method in that route
it's like a standard method like that this :
public function actionUpdate($id){
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('update', ['model' => $model]);
}
}
?
Yes, it's route. In other words, it is combination of controller and action ids with the slash (/
).
For example for NewsController
and actionUpdate()
it will be: news/update
.
If news
is a module with DefaultController
and actionUpdate()
it will be: news/default/update
.
Is it more clear now?
My question is script inside method for update
like :
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('update', ['model' => $model]);
}
You don't have to add anything inside update
action. Just add fillingRoute
as string to behavior parameters:
'fillingRoute' => 'news/update',