I've read the forum posts over and over again but I just can't find where the problem is.
I have Model_ArtworkProfile that has_many Model_ArtworkEdition:
Model_ArtworkProfile:
protected static $_has_many = array(
'editions' => array(
'key_from' => array('id'),
'model_to' => 'Model_ArtworkEdition',
'key_to' => array('artwork_profile_id'),
'cascade_save' => true,
'cascade_delete' => true,
));
Model_ArtworkEdition:
protected static $_belongs_to = array(
'artwork_profile' => array(
'key_from' => array('artwork_profile_id'),
'model_to' => 'Model_ArtworkProfile',
'key_to' => array('id'),
'cascade_save' => true,
'cascade_delete' => false,
)
);
When I delete the artwork profile I want all of its artwork_editions cascade_deleted too, but I am getting the 'Primary key cannot be changed'.
I've re-read I think all posts relating to this issue, but I just can't figure it out.
From this post http://fuelphp.com/forums/topics/view/9975 I am deducing that I would need a 'artwork_profile_id' in artwork_profiles table - is this correct?
Could you please help clarify this issue?
The only rule when it comes to keys and relations is that you can not have a table in which the primary key is also the foreign key.
Which in a one-to-many that is never a problem, since your foreign key is not unique, and therefore can not be the primary key.
In this case, the foreign key is in Model_ArtworkEdition, so that table needs both an 'id' (it's own primary key) and 'artwork_profile_id' (the foreign key pointing to Model_ArtworkProfile). So your relation definitions look correct.
Thank you Harro, for being so generous with your time. This clarification is as simple as its helpful - I've realised that my issue lay elsewhere. Thank you!!!