Open vsuaste opened 4 years ago
Consider the following problems and their solutions presented in this document.
Basically in the context of the above examples and identified problems:
Both above sub-issues should be implemented in the data model layer within the "create" and "update" functions that receive the respective "toAdd" and "toRemove" arguments. Consider writing a helper function, if that appears to maintain the code-base simpler and more concise.
An inverse to-one association is called inverse, if and only if the targetKey is in the associated model. The association technically is a to-many, to enforce the uniqueness a respective constraint, if supported by the underlying storage, or a respective validation has to be implemented. In the latter validation case potential performance issues may arise, e.g. in case a very large Cassandra database has to check for uniqueness of the targetKey.
Hence, the decision of how to implement this has to be the programmer's (user's). The code-generator should just print a warning to the console in case an inverse to-one association is defined in the respective model,json file. The warning should say:
Creating an INVERSE to-one association. You have to manually implement a UNIQUE CONSTRAINT, if supported by the storage, or use a respective UNIQUE validation of attribute XYZ in model ZXY
UPDATE: See the comment below from @asishallab which deprecates the following job-description:
DEPRECATED job-description The migration files need to create
FOREIGN KEY( <foreign_key_as_defined_in_associations.json>)
constraints. Use theON DELETE SET NULL
option. Also add anINDEX
on the foreign key to enable efficient searching.