Do reverse references in Page Manager work with either Entity Reference or References? Perhaps I am doing this wrong. I've attached an export of my variant; if anything else is needed, of course please let me know.

I am using what I understand to be "reverse" references in two content types (node bundles) under Drupal 7 (that is how it seems to work with Context Admin and it makes for a little cleaner information structure in my use case).

I am using a LAMP stack with D 7.14, CTools 7.x-1.0, Entity Reference 7.x-1.0-rc3 (or Reference 7.x-2.0). I also tried the entity_reference-add-cTools-relationship-1340748-33.patch found at http://drupal.org/node/1340748 to no effect. It appears that Entity Reference support was added to CTools in 7.x-1.0-rc2 with "#1394124 by helior and fabsor: Properly reference foreign keys (fixes entityreference relationships)". I also found entity-from-schema: Add the relation in the reverse direction which appears to be committed to a much earlier version. So I suspect I'm doing something wrong.

I have content type A and content type B which has an Entity Reference (also tried node reference) to content type A. If I set up a page variant for B, I can easily use A's fields. But if I set up a variant for A, I can not access B's fields.

I added a "Node from Node" relationship based on the Entity Reference field on B. I then added a "node content" pane based on that relationship. However it displays node A not B. This is somewhat to be expected. What I was not expecting is the lack of a reverse relationship as appears in Views.

I am able to use a views context in page manager so there is a work-around. However this would appear to be a work-around for the use case when we only want e.g. one field from one referencing node because it adds an entire view for a rather simple case that could be handled from within page manager.

Am I missing something (and what is it)? Or is this possibly intended behavior?

Thanks for any pointers,
Eric

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

merlinofchaos’s picture

At the moment, reverse references are not working. There is some commented out code that attempted to implement them, and then I ran into a problem I couldn't solve:

Let's say I have entity type A and it has an entityreference that references entity type B.

I have an entity B, and I want a reverse reference to the entity A that references entity B. But when I run the query, I get 2.

I have no way to determine which one to use. I can use the first one i come across, but that's essentially random. I couldn't come up with a solution to resolve this satisfactorily.

In the meantime, the unfortunate workaround is to write your own relationship plugin that does the right thing in your case. :(

eric__’s picture

Got it. Thank you for so quickly clearing that up.

As an aside, is the logic you described different from views - which, as far as I see from using it, returns 1 row based on the same reverse reference?

Anyway, as a matter of perspective, I'm not so sure the workaround is "unfortunate". While it does limit what may be done with the stock implementation of ctools, it would appear to me that the plugin system actually provides the very flexibility that one would need for 'edge' cases. Perhaps "unfortunate" is too strong a word.

Thanks again,
Eric

merlinofchaos’s picture

Views returns as many rows as you need. With Views you can happily add filters and sorts and whatever to find the one you want.

Another thing you can do is use a view context, which you can use to take a context in, and then create a relationship on the view context to get one out. That's the non-coding method. It can be somewhat complex but it can get the job done.

eric__’s picture

Yup. That's exactly what I did while exploring to get my facts straight. What I didn't realize then was what your explanation makes perfectly clear - Views gives us the query flexibility that reverse references require.

Thanks so very much for your time. You have created some great modules. But it's answeres to questions like this that, while I'm sure draining, make all the difference to users like myself.

Eric

izaiah’s picture

Status: Active » Needs review
FileSize
2.36 KB

Here is a patch that gives reverse entity references from schema. It does not solve the problem merlinofchaos mentions in #1 but it will work for 1to1 relationships. I'm running this in production with no issues.

DamienMcKenna’s picture

Version: 7.x-1.0-rc2 » 7.x-1.x-dev

Chris Matthews’s picture

The 6 year old patch in #5 to entity_from_schema.inc still applies cleanly to the latest 7.x-1.x-dev, but still needs an official RTBC before it can be committed.

entity_from_schema.patch:10: trailing whitespace.
              
entity_from_schema.patch:21: trailing whitespace.
  
entity_from_schema.patch:29: trailing whitespace.
    
entity_from_schema.patch:43: trailing whitespace.
      
Checking patch plugins/relationships/entity_from_schema.inc...
Applied patch plugins/relationships/entity_from_schema.inc cleanly.
warning: 4 lines add whitespace errors.
MustangGB’s picture

Category: Support request » Feature request