Score:1

Find content with missing entity reference

za flag

I have nodes that have embedded Media (images) and also links to other content (nodes and media). Through hooks I populate custom fields to store those references, this is a multi-value entity reference. Also, since the entity reference is an int, the default filter is equals, between, less or greater, etc - 'not in' is not even possible via the UI.

What I would like to do is create a View that would find content where those references are no longer valid; ie. the referenced entity has been removed.

I attempted to use a few hook_views_XXX functions to alter the query or filter the results after execution. Altering the query makes the most sense, but am not sure how to add an IN clause for a custom field. Filtering the results 'post_execute' will be cumbersome since there is not a way good way to get all results before the pager is initialized.

Creating a custom views filter is going to be the next attempt, but would think/hope that there is a simpler way. Is there something I am overlooking? How can the 'query_alter' be done?

Jaypan avatar
de flag
Why do you need to alter the query? Why won't a filter work?
za flag
If a filter can be done that is great, but I can not figure out how to do a 'NOT IN' with a multi value entity reference field.
Jaypan avatar
de flag
You should add the 'multi value' part to the original post, as it's a fairly important bit of context.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.