We have a problem with our migration from CakePHP 2.10 to 3. Some of our Models use HABTM relations and use the
unique key with value:
unique: boolean or string keepExisting.
If true (default value) CakePHP will first delete existing relationship records in the foreign keys table before inserting new ones. Existing associations need to be passed again when updating.
When false, CakePHP will insert the specified new relationship records and leave any existing relationship records in place, possibly resulting in duplicate relationship records.
When set to keepExisting, the behavior is similar to true, but with an additional check so that if any of the records to be added are duplicates of an existing relationship record, the existing relationship record is not deleted, and the duplicate is ignored. This can be useful if, for example, the join table has additional data in it that needs to be retained.
What is the CakePHP 3 equivalent of this key? I read something about
through, and the
dependent key seems like it could help but I can’t quite combine these two in my head completely. What do I need to do to associate 2 Models with each other and not delete the connection entries in my join table but let CakePHP ignore them.
- dependent : When the dependent key is set to
false, and an entity is deleted, the data of the join table will not be deleted.
- through : Allows you to provide either the alias of the Table instance you want used on the join table, or the instance itself. This makes customizing the join table keys possible, and allows you to customize the behavior of the pivot table.