I have a bunch of models that are related in the following way.
(View Attached Photo it would not let me imbed it because this is my first post)
My main model with the controller is Recipe_Category.
in actionCreate() I have the following:
// Uncomment the following line if AJAX validation is needed
$recipes->recipe_category = $model->recipe_category;
$recipeSteps->recipe_id = $recipes->recipe_id;
$recipeImages->recipe_id = $recipes->recipe_id;
//$recipeIngredients->recipe_id = $recipes->recipe_id;
However, only Recipe_Category and Recipes will save to the database and when I display the results in the View Recipes shows "Not Set"
I’m finding Yii to be more confusing than If I did all of this with standard PHP/MySQL
$recipes->recipe_id might be NULL when you try to assign it to $recipeSteps->recipe_id and $recipeImages->recipe_id.
Assuming that $recipes->recipe_id is an auto incremental PK, you have to save $recipes before you assign the recipe_id to others.
Duh, Now I feel stupid that makes sense.
I had to deal with something like that, it may help, I am not sure its the best way to do! I am learning programming in the same time as Yii
I’ve used an extension made by Alexander Kochetov I am looking for the way to make it save my models* , till now I can only validate all models in the same form.
- The doc explain how to do it, but my English don’t really understand everything, i have to translate part by part
what i did to save, is pass false to the save method for each model, after validating everything of corse,
and in the process of saving under a transaction, I affect each insertedID to the FK
// saving process with affectation of ids to the Foreign Keys
like that you should be sure to have everything on the database or nothing I hope