Hi Everyone
I am curious about unique entries and orphaned records. A couple of examples:
a. a DataObject based list of towns (how do we prevent the same town from accidentally being added twice).
b. a Many-to-Many relationship between users and ice-cream flavours. How do we make sure the same flavour is not entered twice AND / OR the same combination does not occur twice (or is that automatically enforced).
We could probably write a few lines in onBeforeWrite that checks if the entry exists and stops the writing from going ahead IF the record already exists, but I am wondering if
a. this is the right way to go about it or should we use Mysql Unique Index?
b. we can create a more universal and faster system
What about orphaning records (e.g. if you have types of icecream (dataobjects) each of which has many flavours (dataobjects) then what happens if you delete a type of icecream, what will happen to those flavours associated with it, will the user get a warning message, etc...)? Is there / should there be a difference in one-to-many and Many-to-Many?
I am working on ecommerce product variations and for both "unique entries" and "orphan records" I wonder "how to do this properly".
Any thoughts are much appreciated.
The way I see it is that, if you try to enter an already existing record then a friendly message comes up "sorry but a record with ... already exists" and the action is cancelled. If you try to delete a record with children then you get a message stating just that and again the action is cancelled. It would be good however, to enforce these cancellations even if the action is not coming from the CMS (e.g. from a $obj->delete()).