Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query::delete() still hard delete #11

Open
steefaan opened this issue Sep 17, 2015 · 2 comments
Open

Query::delete() still hard delete #11

steefaan opened this issue Sep 17, 2015 · 2 comments

Comments

@steefaan
Copy link

First of all, it's an awesome plugin you have written. Unfortunately I have a problem in combination with FriendsOfCake/crud and the bulk delete action. As you can see here the bulk delete action uses Query::delete() to build the delete query. This will generate a hard delete query which is not modified from the soft delete plugin. Probably this issue also occurs in other use cases than crud.

A possible solution would be to overwrite the delete() method inside ORM/Query.php which already exists in your plugin. @PGBI What do you think?

@PGBI
Copy link
Owner

PGBI commented Sep 18, 2015

Unfortunately, I can't override what's done by an other plugin. Even if I overwrite the delete() method inside \SoftDelete\ORM\Query, it won't help since in your example Crud won't be using \SoftDelete\ORM\Query::delete() anyway, it is calling directly \Cake\ORM\Query::delete().

@steefaan
Copy link
Author

@PGBI It should be possible to override it in \SoftDelete\ORM\Query because CRUD is in the correct context. Take a look to the output of debug($query); I placed before this line.

object(SoftDelete\ORM\Query) {

    '(help)' => 'This is a Query object, to get the results execute or iterate it.',
    'sql' => 'SELECT Users.id AS `Users__id`, Users.role_id AS `Users__role_id`, Users.slug AS `Users__slug`, Users.username AS `Users__username`, Users.email AS `Users__email`, Users.email_token AS `Users__email_token`, Users.first_name AS `Users__first_name`, Users.last_name AS `Users__last_name`, Users.password AS `Users__password`, Users.birthday AS `Users__birthday`, Users.gender AS `Users__gender`, Users.status AS `Users__status`, Users.last_login AS `Users__last_login`, Users.deleted AS `Users__deleted`, Users.modified AS `Users__modified`, Users.created AS `Users__created` FROM users Users WHERE (id IN (:c0) AND Users.deleted IS NULL)',
    'params' => [
        ':c0' => [
            'value' => '1a87eba0-2f98-4677-850d-fa6e321a9830',
            'type' => 'string',
            'placeholder' => 'c0'
        ]
    ],
    ...

As you can see, this query is already fine but here the query will be changed to a DELETE query. After this line, the query looks like the following:

object(SoftDelete\ORM\Query) {

    '(help)' => 'This is a Query object, to get the results execute or iterate it.',
    'sql' => 'DELETE FROM users WHERE id IN (:c0)',
    'params' => [
        ':c0' => [
            'value' => '4a6ed4ef-b713-41c8-a8b9-1a70f226e2a3',
            'type' => 'string',
            'placeholder' => 'c0'
        ]
    ],

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants