Implicit Save Vs Explicit Save
Posted 06 February 2013 - 01:26 PM
Media - id, object_id
Object - id, type(product,media)
Product table belongs to Object table
Media table belongs to Object table.
Whenever a Product/media is created an object_id needs to be created. So should i explicitly create a entry in object table and assign it to object_id in controller or do it in model in beforeSave method.
Also i don't want product to be created if a object is not created. So if i am using 2nd way is there a way to prevent save of product if object is not created.
My preferred way is 2. Would like to know your thoughts on each one.
Posted 06 February 2013 - 02:11 PM
I prefer second one.
We can make a check by two ways.
1.We can use CActiveRecord::exists method to check the existance of an object by ralational attribute,
in a custom validator method.
2.We can use CExistValidator
This is what YII says in API.
This validator is often used to verify that a foreign key contains a value that can be found in the foreign table.
Posted 06 February 2013 - 03:36 PM
Posted 06 February 2013 - 05:15 PM
Posted 07 February 2013 - 10:12 PM
Thanks so is there a way i can communicate back saying object creation failed