Answer the question
In order to leave comments, you need to log in
What to do with the object when deleting information from the database?
Hello gentlemen!
I am tormented by one sensitive question - who implemented the handling of such a case: there was an object (let's say ActiveRecord), delete () was thrown from it, and the record in the database was deleted.
What should happen to the object next, since it cannot delete itself? Do the isDeleted flag, clear the data inside, just forget about it?
Answer the question
In order to leave comments, you need to log in
If the goal is to provide for any situations, then apparently it is necessary to set a flag and, when trying to do something with such an object, throw an exception.
After deleting the object, you can still erase the value of the primary key - then, if anything, you can directly insert the same object into the database “on a new one”.
In general, ActiveRecord
this is a bad practice, which was abandoned long ago in JAVA ORM frameworks, so as not to clog domain objects with extraneous logic (responsible for their preservation), which can change. Now it's correct - entityManager.delete(object)
.
In general, the presence of strongly complex methods in an object (i.e., those that take other similar objects as arguments, and not just primitives), in a situation where it is impossible to add methods at runtime, is tight coupling and, therefore, bad practice.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question