You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, thanks for sucha good library. But I have some doubts about related records deleting in case of HAS_MANY relation. For example if I have model Question which has many questions and only one right question i would implement it in DB like such:
So, when i'm inserting it's okay all stuff save correctly. But when I'm trying to update relation, I'm getting an error, because of deleting records from variant which is dependency of question. So what do you think about this situation? My suggestion is to add a check for a changes in related records list and remove only deleted records.
The text was updated successfully, but these errors were encountered:
So if I'm trying to update question with new variants:
$question = Question::model()->findByPk($_POST['quesiton_id']);
//I already have $question->rightVariant with id=1, and also I have this entry in $_POST['Variant'] array$variants = array();
foreach($_POST['Variant'] as$rawVariant){
$variant = Variant::model()->findByPk($rawVariant['id']);
$variant->attributes = $rawVariant;
$variants[] = $variant;
}
$question->variants = $variants;
$question->save(); //here i have foreign key constraint violation, because of deleting variant with id=1 by EActiveRecordBehavior
Hello, thanks for sucha good library. But I have some doubts about related records deleting in case of HAS_MANY relation. For example if I have model Question which has many questions and only one right question i would implement it in DB like such:
So, when i'm inserting it's okay all stuff save correctly. But when I'm trying to update relation, I'm getting an error, because of deleting records from variant which is dependency of question. So what do you think about this situation? My suggestion is to add a check for a changes in related records list and remove only deleted records.
The text was updated successfully, but these errors were encountered: