Skip to content

Models can be deleted directly... but they shouldn't be #1111

Description

@jwoertink

Not sure why I never noticed this before, but we have this method:

def delete
self.class.write_database.exec "DELETE FROM #{@@table_name} WHERE #{primary_key_name} = #{escape_primary_key(id)}"
end

This means you can do this

user = UserQuery.find(1)
user.delete
SaveUser.update!(user)

The issue here is that this sort of breaks the repository pattern, and also circumvents the whole point of Delete operations. You can't run any other SQL directly against a model, so deleting a model directly should also be restricted.

I didn't look too far in to it, but it's possible this existed before we added DeleteOperations... In any case, we should deprecate the direct use of calling model.delete, then later remove it so you have to use a DeleteOperation instead (or bulk query).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions