6

Don't people learn the basics of how things work anymore ?!

I am cleaning this project, where some juniors have implemente a lot of the code.

Apparently, the way of deleting an entity from the database is:

1) SELECT the entire row and cast it to a model class

2) CONVERT that model class to a DTO class

3) READ the Id property from the DTO class

4) SELECT the entire row, again, and this time cast it to a DTO class

5) CONVERT that DTO class to a model class

6) Use you pancy-pants ORM delete method using the entire model class as input argument..

FUCK YOU !

inb4 what about reference checks ?
- Nope. That is done separately using only the Id

inb4 what about checking if someone else has altered it before deleting
- Nope, the entire entity is not used for that either.

Comments
  • 0
    @devnulli we have tiers. That was the interaction between the lowest and next lowest tier
  • 1
    Well, yes and no. We don't have a domain model that is 100% separated from the rest.

    1 is the repository layer which accepts a key to retrieve the entity.

    4 is the service layer calling the repository layer (gets the model) and then the service layer converts it to a DTO

    2,3 and 5 is the service layer, that checks for references using the key and nothing but the key.

    6 is the repository layer again.

    To clarify my point, since we already have the key and use only the key, why would someone implement this abomination instead of a repository Delete method that just accepts the key ?
  • 1
    You know, even with ORMs you can perfectlly do a "delete from .. where id = XX" without actually wrting any manual SQL.

    And MOST ORMs are already implementing repisitory pattern, no need to add another layer.
Add Comment