Product - id, object_id
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.
Page 1 of 1
Implicit Save Vs Explicit Save
#2
Posted 06 February 2013 - 02:11 PM
Dear Friend
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.
Regards.
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.
Quote
CExistValidator validates that the attribute value exists in a table.
This validator is often used to verify that a foreign key contains a value that can be found in the foreign table.
This validator is often used to verify that a foreign key contains a value that can be found in the foreign table.
Regards.
#4
Posted 06 February 2013 - 05:15 PM
Create the Object record in the beforeSave() method in your Product/Media models. If the save() on the Object record returns false (=fails) then simply return false from beforeSave() and it will not save the Product/Media record.
#5
Posted 07 February 2013 - 10:12 PM
Mike, on 06 February 2013 - 05:15 PM, said:
Create the Object record in the beforeSave() method in your Product/Media models. If the save() on the Object record returns false (=fails) then simply return false from beforeSave() and it will not save the Product/Media record.
Thanks so is there a way i can communicate back saying object creation failed
Share this topic:
Page 1 of 1