PGBI/cakephp3-soft-delete

Problem with query->orWhere()

stefanozoffoli opened this issue · 5 comments

Hi,
can you please read this ticket cakephp/cakephp#6407 ?

Thank you!

PGBI commented

I'm in vacation right now. I'll see how to fix this once returned. Thx for reporting!

PGBI commented

@stefanozoffoli It should be solved now. Can you please confirm?

Sorry for the late response. There is now another problem with belongsToMany queries.

Esample:
PostsTable belongsToMany LabelsTable
In the database, each posts, labels, labels_posts has deleted field.

Database has these records:

posts (id, title, deleted):
(1, 'First article', null);

labels (id, title, deleted):
(1, 'First label', null),
(2, 'Second label', null);

labels_posts (id, post_id, label_id, deleted):
(1, 1, 1, '2015-05-05 11:48:27'),
(2, 1, 2, null);

When I select posts, both first and second labels are selected and associated to the article despite the deleted record in the bridge.

Here is the generated sql:

SELECT Posts.id AS `Posts__id`, Posts.title AS `Posts__title`, Posts.deleted AS `Posts__deleted`
FROM posts Posts
WHERE Posts.deleted IS NULL
ORDER BY Posts.id DESC
LIMIT 20
OFFSET 0

SELECT LabelsPosts.label_id AS `LabelsPosts__label_id`, LabelsPosts.id AS `LabelsPosts__id`, LabelsPosts.post_id AS `LabelsPosts__post_id`, LabelsPosts.deleted AS `LabelsPosts__deleted`, Labels.id AS `Labels__id`, Labels.title AS `Labels__title`, Labels.deleted AS `Labels__deleted`
FROM labels Labels
    INNER JOIN labels_posts LabelsPosts
    ON Labels.id = (LabelsPosts.label_id)
WHERE (LabelsPosts.post_id in (:c0) AND Labels.deleted IS NULL)

So Query does not add deleted condition to LabelsPosts.

Thank you!

PGBI commented

Doesn't seem to be related to the original issue with orWhere(). Do you mind creating a new issue for the belongsToMany issue? Thx!