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
cascade delete not working
$country = Model_Country::find($id);
$country->delete();
Error
Primary key on model Model_Country_Translation cannot be changed.
Please help me fix this
The text was updated successfully, but these errors were encountered:
I may be misspeaking but for cascade delete to work you have to prefetch
all relationships you want to delete, such as:
$country = Mode_Country::query()->related('translations')->where('id',
$id)->get_one();
$country->delete();
On Wed, Mar 10, 2021 at 10:20 AM hotlabs ***@***.***> wrote:
im have
protected static $_has_many = array(
'translations' => array(
'key_from' => 'id',
'model_to' => 'Model_Country_Translation',
'key_to' => 'country_id',
'cascade_save' => true,
'cascade_delete' => true,
)
);
protected static $_primary_key = array('country_id', 'language_code');
protected static $_properties = array(
'country_id',
'language_code',
'name',
'slug',
'description',
'meta_title',
'meta_description',
'meta_keywords',
);
cascade delete not working
$country = Model_Country::find($id);
$country->delete();
Error
Primary key on model Model_Country_Translation cannot be changed.
Please help me fix this
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#446>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABHOFW2ZPOMER2OXVFVJ3OTTC6E5NANCNFSM4Y6HWESQ>
.
The parent model defines "country_id" as the primary key of the related table, but the related model defines a compound primary key. So it won't delete, it will try to detach, and you get the error because it sets the keys to NULL.
To know for sure you'll need to check the backtrace.
im have Relation
protected static $_has_many = array(
'translations' => array(
'key_from' => 'id',
'model_to' => 'Model_Country_Translation',
'key_to' => 'country_id',
'cascade_save' => true,
'cascade_delete' => true,
)
);
---------------Model_Country_Translation
protected static $_primary_key = array('country_id', 'language_code');
protected static $_properties = array(
'country_id',
'language_code',
'name',
'slug',
'description',
'meta_title',
'meta_description',
'meta_keywords',
);
cascade delete not working
$country = Model_Country::find($id);
$country->delete();
Error
Primary key on model Model_Country_Translation cannot be changed.
Please help me fix this
The text was updated successfully, but these errors were encountered: