Skip to content
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

Open
hotlabs opened this issue Mar 10, 2021 · 2 comments
Open

Cannot delete relations #446

hotlabs opened this issue Mar 10, 2021 · 2 comments

Comments

@hotlabs
Copy link

hotlabs commented Mar 10, 2021

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

@nickhagen
Copy link

nickhagen commented Mar 10, 2021 via email

@WanWizard
Copy link
Member

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants