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

[4.x]: relations table not being cleaned up when editing entry types #13956

Closed
ryssbowh opened this issue Nov 22, 2023 · 3 comments
Closed

[4.x]: relations table not being cleaned up when editing entry types #13956

ryssbowh opened this issue Nov 22, 2023 · 3 comments
Assignees

Comments

@ryssbowh
Copy link

What happened?

Description

I'm not sure this is intended but the relations table doesn't seem to be cleaned up when removing a field from an entry type, and querying relatedTo elements does return results where it shouldn't.

If you have an entry type that contains let's say an asset field, and an entry with some value in it ($element in the following query). Then remove the field from the entry type. The query :

Entry::find()->relatedTo(['targetElement' => $element])->all()

still returns results.

I've resaved those entries, ran gc, but they're still in the relations table.

Steps to reproduce

  1. Create an Asset field
  2. Add the field to an Entry type
  3. Create an entry of that type
  4. Remove the asset field from the entry type
  5. Run the query above

Expected behavior

That query doesn't return results

Craft CMS version

4.5.11

PHP version

8.2

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

@i-just i-just self-assigned this Nov 23, 2023
@i-just
Copy link
Contributor

i-just commented Nov 23, 2023

Hi, thanks for getting in touch!

Relations are removed from the relations table in the following cases:

  • when the relation is removed via the field
  • when the field is deleted (not removed from the field layout, but deleted)
  • when the source of the relation is deleted
  • when the target of the relation is deleted

In the last 2 cases, Garbage Collection might be involved before the relations are deleted (because of the soft-delete feature).

We don’t, however, touch the relations when the field is removed from the layout. I don’t think we’d like to start doing this routinely, but we’ll discuss some options internally.

@brandonkelly
Copy link
Member

We decided to start deleting “leftover” relations after element save, starting in Craft 4.8 (#14368).

@brandonkelly
Copy link
Member

Craft 4.8.0 is out now with that change.

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

No branches or pull requests

3 participants