-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot delete relations #446
Comments
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 problem here is most likely the key mismatch. 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. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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: