A
A
arturgspb2012-10-22 15:57:53
OOP
arturgspb, 2012-10-22 15:57:53

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

3 answer(s)
E
egorinsk, 2012-10-22
@egorinsk

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.

F
Flammar, 2012-10-23
@Flammar

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, ActiveRecordthis 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.

G
gleb_kudr, 2012-10-23
@gleb_kudr

Definitely a flag. And then periodically clean + vacuum the database.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question