Problem/Motivation

1) Add same paragraph field to comments and node entities
2) create a view of paragraph items
3) add relationships to comment and node tables from paragraph item.
4) add node title and comment title
Expected: if paragraph item attached to node, shows node title. for paragraph item attached to comment, shows comment title
Actual: if there is a paragraph item attached to a node with the same id (nid: 15) as comment (cid: 15), it shows the node titles and the same id comment title.

Proposed resolution

I suggest we fully rely on what's views itself is doing:

  • Files: https://cgit.drupalcode.org/views/tree/modules/file.views.inc?id=72f907f...
  • Image: https://cgit.drupalcode.org/views/tree/modules/image.views.inc?id=72f907...
  • Taxonomy: https://cgit.drupalcode.org/views/tree/modules/taxonomy.views.inc?id=84f...

  • All define following extra conditions for the join:

        'join_extra' => array(
            0 => array(
              'field' => 'entity_type',
              'value' => $entity_type,
            ),
            1 => array(
              'field' => 'deleted',
              'value' => 0,
              'numeric' => TRUE,
            ),
          ),
    

    Remaining tasks

    Needs reviews.

    User interface changes

    None

    API changes

    None.

    Data model changes

    None.

    Support from Acquia helps fund testing for Drupal Acquia logo

    Comments

    hefox created an issue. See original summary.

    hefox’s picture

    Status: Active » Needs review
    FileSize
    577 bytes
    jeroen.b’s picture

    Status: Needs review » Needs work

    Could you maybe add a test for this?

    das-peter’s picture

    Issue summary: View changes
    Status: Needs work » Needs review
    FileSize
    698 bytes

    I can second this - without the entity type condition you'll get funky results once a paragraphs field is used on multiple entity types.
    I suggest we fully rely on what's views itself is doing:

  • Files: https://cgit.drupalcode.org/views/tree/modules/file.views.inc?id=72f907f...
  • Image: https://cgit.drupalcode.org/views/tree/modules/image.views.inc?id=72f907...
  • Taxonomy: https://cgit.drupalcode.org/views/tree/modules/taxonomy.views.inc?id=84f...

  • All define following extra conditions for the join:

        'join_extra' => array(
            0 => array(
              'field' => 'entity_type',
              'value' => $entity_type,
            ),
            1 => array(
              'field' => 'deleted',
              'value' => 0,
              'numeric' => TRUE,
            ),
          ),
    

    Added an updated patch and updated ticket summary.

    • jstoller committed ffc33ea on 7.x-1.x authored by das-peter
      Issue #2560601 by hefox, das-peter: Need to join on entity type when...
    jstoller’s picture

    Status: Needs review » Fixed

    Patch committed to dev.

    Status: Fixed » Closed (fixed)

    Automatically closed - issue fixed for 2 weeks with no activity.