Views doesn't recognize relationship to host

Created on 13 September 2016, about 8 years ago
Updated 16 January 2023, almost 2 years ago

Steps to reproduce:

There's many ways to reveal this bug. For example a view of nodes related to paragraphs, or a view of paragraphs related to the parent entity like so:

  • Set up a node with a paragraph field (field_x) and a paragraph in it with some content.
  • Create a view page that displays paragraphs.
  • Add a relationship on "Content using field_x", set it to required.
  • View the page for the view, observe that it has no entries.

The paragraph should appear on the view page since it is referenced by "Content using field_x". You can set up something similar with 2 different node types and a regular entity reference field and see that it does display the referenced entity.

There's probably many other combinations of view of X related to Y that will reveal this bug.

Remaining tasks

  • Write a hook_update_N() to migrate views' relationships (and fields/filters/sorts/arguments that use those relationships) to the new format. see #124 for details
  • There's some reports of broken filters due to this patch. #151
  • There's some reports of old revisions showing in views due to this patch.
  • There's some reports of missing paragraphs in views for a multi-value ERR Paragraphs field due to this patch.
  • There's some reports of duplicate rows when having a delta field due to this patch. #134 and others
  • This patch causes some UX confusion because there's now multiple ways to connect a paragraph to its parent entity in Views. #151
  • ...Could be more bugs, I only read back the last year's worth of comments on this issue...

How to apply patches

If you need to know how to use a patch, please take a look at
https://www.drupal.org/docs/develop/git/using-git-to-contribute-to-drupa... โ†’
and
https://www.drupal.org/docs/develop/git/using-git-to-contribute-to-drupa... โ†’
please don't muddy this issue with questions about how to apply a patch.

๐Ÿ› Bug report
Status

Needs review

Version

1.0

Component

Code

Created by

๐Ÿ‡จ๐Ÿ‡ฆCanada jmuzz

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States ja09

    6 years and running to get one of most popular Drupal modules to work properly with views?

    Sorry to sound like a hater, this issue killed my day and I'm shit posting. #176 doesn't work under certain circumstances, like with workflows when the content isn't published. I wish I could contribute, but as a lowly front-end guy there's probably not much I can do. I will contribute monetarily though if there's a transparent way for me to do that.

  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany vistree

    For me applying patch from #176 duplicates the paragraphs in some cases. I can't find a rule for this problem Anyone else seing this problem?

  • Status changed to Needs work over 1 year ago
  • ๐Ÿ‡ณ๐Ÿ‡ฑNetherlands ifrik

    I'm a bit confused with the state of the different patches in here, but #158 works on 9.5.3.

    However, when adding a relationship I have a duplication for "Content using [field_name]" and one of them works, while the other doesn't.

    Setting this to "Needs work" according to comment 185.

  • First commit to issue fork.
  • ๐Ÿ‡จ๐Ÿ‡ฆCanada spotzero

    I've rebased the issue fork and it seems to work for me. I've not sure how the issue fork has diverged from the latest patch though.

  • ๐Ÿ‡ฆ๐Ÿ‡นAustria attisan Vienna

    +1 for the MR 5.

  • Just tested MR5 from #187 and it fixed this issue for me.

    Thanks,

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States jchand

    is a patch available for issue number 187? thx

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States jchand

    Thanks, abx. Seems to be working for me.

  • Status changed to Needs review over 1 year ago
  • ๐Ÿ‡ณ๐Ÿ‡ฑNetherlands neograph734 Netherlands

    Setting NR for #187

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States SocialNicheGuru

    Will update hooks be added to this issue or will that be another issue?

  • ๐Ÿ‡จ๐Ÿ‡ฆCanada spotzero

    @SocialNicheGuru what update hooks are you referring to? It's been a while since I looked at this issue, but I didn't think it needed an update hook.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States SocialNicheGuru

    Comment #124 ๐Ÿ› Views doesn't recognize relationship to host Needs work outlines the need for update_hook as well as #125: Who's Online and Chatbox โ†’

    This breaks old views when applied.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States SocialNicheGuru

    I am also having an issue.
    My slideshow view
    relationship
    paragraph referenced by slideshow_paragraph_ref

    slideshow_paragraph_ref points to slideshow paragraph type

    I can add the new relationships fine.
    When I try to then add fields from my specific paragraph the fields are not there.

    I have access to generic paragraph fields

    Admin title (admin_title)	Paragraph	The admin title is used to help identify paragraphs when using them as blocks.
    Update Authored on (created)
    Authored on (created)	Paragraph	The time that the Paragraph was created.
    Update Behavior settings (behavior_settings)
    Behavior settings (behavior_settings)	Paragraph	The behavior plugin settings
    Update Default translation (default_langcode)
    Default translation (default_langcode)	Paragraph	A flag indicating whether this is the default translation.
    Update ID (id)
    ID (id)	Paragraph	
    Update Link to Paragraph (view_paragraph)
    Link to Paragraph (view_paragraph)	Paragraph	Provide a view link to the Paragraph.
    Update Original language (langcode)
    Original language (langcode)	Paragraph	The paragraphs entity language code.
    Update Paragraph type (type)
    Paragraph type (type)	Paragraph	
    Update Parent field name (parent_field_name)
    Parent field name (parent_field_name)	Paragraph	The entity parent field name to which this entity is referenced.
    Update Parent ID (parent_id)
    Parent ID (parent_id)	Paragraph	The ID of the parent entity of which this entity is referenced.
    Update Parent type (parent_type)
    Parent type (parent_type)	Paragraph	The entity parent type to which this entity is referenced.
    Update Publish on (publish_on)
    Publish on (publish_on)	Paragraph	
    Update Published (status)
    Published (status)	Paragraph	
    Update Rendered entity (rendered_entity)
    Rendered entity (rendered_entity)	Paragraph	Renders an entity in a view mode.
    Update Revision ID (revision_id)
    Revision ID (revision_id)	Paragraph	
    Update Revision translation affected (revision_translation_affected)
    Revision translation affected (revision_translation_affected)	Paragraph	Indicates if the last edit of a translation belongs to current revision.
    Update Translation language (langcode)
    Translation language (langcode)	Paragraph	The paragraphs entity language code.
    Update Unpublish on (unpublish_on)
    Unpublish on (unpublish_on)	Paragraph	
    Update UUID (uuid)
    UUID (uuid)	Paragraph
    
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States SocialNicheGuru
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States SocialNicheGuru

    Thank you #124
    I had to goto my effected view
    do a search and replace and add "_target_id" to ERR in my view
    so field_paragraph became field_paragraph_target_id
    I deleted the view
    I had mine in a feature/config so did a drush features-import feature name you can do a config-import.
    And all is good in the world again.

  • First commit to issue fork.
  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 9.5.x + Environment: PHP 7.3 & MySQL 5.7
    last update over 1 year ago
    28 pass, 4 fail
  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia acbramley

    I've pushed the missing filter plugin and tests to the MR.

    To keep this issue sane and in any hope of getting committed, please do not post any more reroll patches of previous patches without tests, etc.

    To generate a patch from the MR, you can do a wget https://git.drupalcode.org/project/entity_reference_revisions/-/merge_requests/5.diff

    And commit the patch locally, you can reference a local patch in composer using "my patch": "./path/to/file.patch"

  • ๐Ÿ‡ช๐Ÿ‡ธSpain google01

    Unfortunately with the latest changes MR5 is causing problems and is not being applied correctly.

  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany luenemann Sรผdbaden, Germany

    @google01 the MR !5 does not apply to a released version because entity_composite_relationship_test.info.yml is changed by drupal.org release packaging.

    As a solution you could switch to a git checkout of entity_reference_revisions like this:

    composer reinstall --prefer-source drupal/entity_reference_revisions
    
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly robertoperuzzo ๐Ÿ‡ฎ๐Ÿ‡น Tezze sul Brenta, VI

    @luenemann I run you composer reinstall command, but the MR !5 still doesn't apply.

  • ๐Ÿ‡ฎ๐Ÿ‡นItaly robertoperuzzo ๐Ÿ‡ฎ๐Ÿ‡น Tezze sul Brenta, VI

    The MR !5 patch works locally using the @luenemann advice, but it doesn't work in my CI/CD pipeline because we use the standard --prefer-dist flag in composer install command.

    So, how can I fix this MR?

  • ๐Ÿ‡ช๐Ÿ‡ธSpain google01

    Although not my first choice to use "dev" modules in production, you can apply the patch by replacing the stable version of the module in composer.json with:

    "drupal/entity_reference_revisions": "1.x-dev",

  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany luenemann Sรผdbaden, Germany

    @robertoperuzzo You can set preferred-intall in composer.json config (https://getcomposer.org/doc/06-config.md#preferred-install) . Use

    composer config preferred-install.drupal/entity_reference_revisions source
    
  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany tobiasb Berlin

    In case someone needs fix-only patch, which does not touch the info file. -> #3371284: Patches - entity_reference_revisions โ†’ ;-)

  • Status changed to Needs work about 1 year ago
  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany Anybody Porta Westfalica

    Back to NW as of the failing tests in #201

  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 10.1.x + Environment: PHP 8.1 & MariaDB 10.3.22
    last update about 1 year ago
    run-tests.sh fatal error
  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany geek-merlin Freiburg, Germany

    Note: All failing tests boil down to:

    Drupal\Core\Config\Schema\SchemaIncompleteException: No schema for views.view.composite_entities
    

    Any idea how to fix this and move this forward? It it's in the comments or the IS, i did not see it.

  • ๐Ÿ‡จ๐Ÿ‡ญSwitzerland berdir Switzerland

    That's because these tests don't have the views module enabled. Moving the config to config/optional should be enough to fix that.

  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 9.5.x + Environment: PHP 8.1 & MariaDB 10.3.22
    last update 12 months ago
    39 pass
  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 9.5.x + Environment: PHP 8.1 & MySQL 5.7
    last update 12 months ago
    39 pass
  • Pipeline finished with Skipped
    11 months ago
    #64550
  • First commit to issue fork.
  • Pipeline finished with Skipped
    11 months ago
    #64551
  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 9.5.x + Environment: PHP 7.3 & MySQL 5.7
    last update 11 months ago
    28 pass, 4 fail
  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 10.1.4 + Environment: PHP 8.2 & MySQL 8
    last update 11 months ago
    39 pass
  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 10.1.4 + Environment: PHP 8.2 & MySQL 8
    last update 11 months ago
    Patch Failed to Apply
  • ๐Ÿ‡ฑ๐Ÿ‡บLuxembourg B-Prod

    Fixes the compatibility with PHP 8.2

    There are 2 version, on declaring the property, the other creating a simple variable. The last version seems more logical, as the property is not used anywhere so it seems useless.

    The patch uses the second variant.

  • ๐Ÿ‡ฑ๐Ÿ‡บLuxembourg B-Prod

    Here is the correct patch, the previous is invalid.

  • ๐Ÿ‡ฑ๐Ÿ‡บLuxembourg B-Prod

    This is not my day... Here is the correct patch, I hope.

  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 10.2.x + Environment: PHP 8.1 & MariaDB 10.3.22
    last update 9 months ago
    run-tests.sh fatal error
  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 10.2.1 + Environment: PHP 8.2 & MySQL 8
    last update 9 months ago
    run-tests.sh fatal error
  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 9.5.x + Environment: PHP 7.3 & MySQL 5.7
    last update 9 months ago
    29 pass, 4 fail
  • Pipeline finished with Failed
    9 months ago
    Total: 176s
    #110265
  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 9.5.x + Environment: PHP 7.3 & MySQL 5.7
    last update 9 months ago
    41 pass
  • Pipeline finished with Failed
    9 months ago
    Total: 273s
    #110282
  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 9.5.x + Environment: PHP 7.3 & MySQL 5.7
    last update 9 months ago
    41 pass
  • Pipeline finished with Success
    9 months ago
    #110309
  • Status changed to Needs review 9 months ago
  • ๐Ÿ‡ท๐Ÿ‡ดRomania vasike Ramnicu Valcea

    This still not closed, after all these years ... hmm

    Updated the MR to make it green
    Used @Berdir #211 suggestion about the some errors.
    + Some new PHP issues that add errors for tests.
    Also merged the latest dev version of module.

    What else is needed here?

    p.s. i think we need to use the MR, instead of patches - to join our efforts ... and maybe hide the patches.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States capysara

    I agree, the patches should be hidden and work should continue in the MR. Hiding patches.

    There are several Remaining tasks in the IS that need to be reviewed. If they're already fixed, then the IS should be updated.

  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 9.5.x + Environment: PHP 7.3 & MySQL 5.7
    last update 8 months ago
    41 pass
  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 9.5.x + Environment: PHP 7.3 & MySQL 5.7
    last update 7 months ago
    Patch Failed to Apply
  • ๐Ÿ‡บ๐Ÿ‡ฆUkraine s.kulyk

    MR patch that is compatible with 1.10 module version. Works for me.

  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 10.2.1 + Environment: PHP 8.2 & MySQL 8
    last update 7 months ago
    Patch Failed to Apply
  • ๐Ÿ‡จ๐Ÿ‡ญSwitzerland maenjuel

    I tried patch #176 and patch #219 and they both solved the issue so the referenced content showing up in views (#176 with an older, stable release of the module, and #219 with the latest dev release). However, I'm not able to remove a paragraph from a view in either version/patch.

    If I edit a node and remove a paragraph, the view still includes the removed paragraph. As a contextual filter I tested both "Paragraph revision: Parent ID" and "Paragraph: Parent ID" and added a filter criteria "Paragraph revision: Is Latest Revision", to see whether it makes a difference.

    Unfortunately it didn't help and now I'm left with a "ghost paragraph".

  • ๐Ÿ‡ฌ๐Ÿ‡ทGreece vensires

    I personally think that this last comment is not related to the issue tackled here unfortunately.

    Your issue seems to be that the there are still paragraph entities having as parent ID your host entity which - from a query perspective - is correct. Maybe your solutions lies on the functionality of paragraphs to remove orphaned paragraphs.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States capysara

    Individuals can generate patches from Merge Requests. Having both patches and MRs in the queue, especially in an 8 year old issue with over 200 comments, will slow down progress.

    For example, there's no MR (or interdiff) for #220 so changes are no longer being tracked, which makes it more difficult for someone to decide what to test. If the patch in #220 is different from the patch in #219, then the MR needs to be updated.

  • ๐Ÿ‡จ๐Ÿ‡ญSwitzerland maenjuel

    Hmm, you might be right @vensires, it could simply be related to the Paragraphs module. There are still some bug reports and forum posts about orphaned paragraphs, so that seems to be a thing.

    I thought it might have to do with this issue since the node edit form doesn't list the (not anymore) referenced paragraph anymore (so the paragraph shouldn't be "related" to the host anymore) and "Delete orphaned composite entities" on /admin/config/system/delete-orphans didn't remove any paragraphs.

  • Status changed to RTBC 6 months ago
  • Tested #220 and works as intended.

  • ๐Ÿ‡ญ๐Ÿ‡บHungary bubu Hungary

    After switching from D9.5 to D10.2 I updated patch from #158 to #220 and it works well again.

  • First commit to issue fork.
  • ๐Ÿ‡ธ๐Ÿ‡ฎSlovenia primsi

    This needed a rebase for me.

  • Pipeline finished with Failed
    6 months ago
    Total: 205s
    #191871
  • Status changed to Needs work 4 months ago
  • ๐Ÿ‡จ๐Ÿ‡ญSwitzerland berdir Switzerland

    Happy that this is close, I posted a review with a few things that should be fairly easy to address.

  • ๐Ÿ‡จ๐Ÿ‡ญSwitzerland berdir Switzerland

    Did some manual testing and this is quite challenging. I know a huge number of people use this and I wanted to get this merged, but it's a lot and complex.

    Right now, the MR *attempts* to define a by-id and a by-revision-id relationship, both direct and reverse.

    However, they have the same keys on the views data definitions, so in practice, only by-id is defined. By-id uses the "By id: " prefix in the label, which is really confusing to users IMHO, it certainly confused me and took me quite a long time to figure this out.

    Additionally, it also defines by-id and by-target-and-host-revision-i references in a loop, which in practice results in _another relationship that does exactly the same and those really are visible duplicates, because they're defined on the respective column for views and not the field name.

    My guess is that over time, things conflicted, were refactored and got copy pasted and merged resulting in this duplicated definition.

    The problem is that both current by-id and the overwritten by-reference-id relationships from the base/data table are kind of wrong. If you have a situation where a default revision of a host entity references a non-default revision of a target entity, both relationships will always show the default revision, because by-revision-id really just joins through the revision table implicitly and will still use the default unless you specifically use fields of the revision relationship:

    SELECT "paragraphs_item_field_data"."id" AS "id", "paragraphs_item_field_data"."langcode" AS "paragraphs_item_field_data_langcode", "field_paragraphs_demo_paragraphs_item_revision_field_data"."vid" AS "field_paragraphs_demo_paragraphs_item_revision_field_data_vi"
    FROM
    {paragraphs_item_field_data} "paragraphs_item_field_data"
    INNER JOIN {paragraphs_item_revision_field_data} "paragraphs_item_revision_field_data" ON paragraphs_item_field_data.revision_id = paragraphs_item_revision_field_data.revision_id
    INNER JOIN {node_revision__field_paragraphs_demo} "node_revision__field_paragraphs_demo" ON paragraphs_item_revision_field_data.revision_id = node_revision__field_paragraphs_demo.field_paragraphs_demo_target_revision_id AND node_revision__field_paragraphs_demo.deleted = '0'
    INNER JOIN {node_field_revision} "field_paragraphs_demo_paragraphs_item_revision_field_data" ON node_revision__field_paragraphs_demo.revision_id = field_paragraphs_demo_paragraphs_item_revision_field_data.vid
    WHERE "paragraphs_item_field_data"."status" = '1'
    LIMIT 11 OFFSET 0
    

    In practice, this should currently rarely happen, because ERR attempts to keep the default revision in sync for entities like paragraphs.

    Still not entirely sure what to do with this. Possibly something like this:

    * Regular reference to the target entity, replacing the current by-id relationship label
    * New regular reference to the target entity *revision*, this will replace the currently overwritten one and will always be the correct data/revision, but revisions are a bit limited in views, you can for example apparently not render them.
    * A single reverse relationship for both the default and the revision table. The default table will only show the host entity and the revision table will only show the host entity revision option. So the current "HostEntity revision using FIELD" relationship will go away when you have a view of TargetEntity (e.g. paragraphs) and not revisions, since per the query above, it's the same, just an doing an extra join.

    This means that existing views relying on the patch might be broken as some relationships will no longer exist, not under their current identifiers anyway.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States recrit

    The MR diff cannot be applied to a stable tag (i.e. 8.x-1.12) due to the changes in tests/modules/entity_composite_relationship_test/entity_composite_relationship_test.info.yml. The attached patch does not include any tests changes so that it can be used in a composer build.

  • ๐Ÿ‡ง๐Ÿ‡ฏBenin delacosta456

    hi
    i confirm the issue mentioned by @recrit . And it's provided patch #231 solve the issue for me

    Thanks

  • ๐Ÿ‡ต๐Ÿ‡ญPhilippines leolandotan

    I have tested the patch from #231 on a site with Drupal Core 10.3.8, Entity Reference Revisions 8.x-1.12 and Paragraphs 1.18 installed. I can confirm that this is fixed when I have added the "Articles with a field_paragraphs set to the Paragraph." relationship.

    I just added a Paragraph field(field_paragraphs) to the Article content type and created a simple view showing Paragraphs with a Relationship and Contextual filter of "Parent ID (Paragraph)".

    Thank you very much!

Production build 0.71.5 2024