Node References on D7 are not working for relationships. They are not even showing up as relationships. This patch attempts to add that back in.

Files: 
CommentFileSizeAuthor
#63 references_relationship_handler-962694.patch5.63 KByched
PASSED: [[SimpleTest]]: [MySQL] 0 pass(es).
[ View ]
#42 references_relationships-962694-42.patch2.66 KByched
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch references_relationships-962694-42.patch.
[ View ]
#25 references-add-base-field-962694-25.patch1.63 KBdas-peter
PASSED: [[SimpleTest]]: [MySQL] 0 pass(es).
[ View ]
#20 references_962694.patch1.6 KBfgm
PASSED: [[SimpleTest]]: [MySQL] 0 pass(es).
[ View ]
#17 node_ref_views_3_d7.patch1.46 KBdawehner
node_ref_views_3_d7.patch1.7 KBmfer

Comments

Status:Needs review» Reviewed & tested by the community

Looks fine

Same here, works like a charm - thanks.

The patch works fine.
Thank you so much!

My environment:
- Drupal 7 beta 1
- Views 7.x-3.x-dev (2010-Oct-19)

Project:Content Construction Kit (CCK)» References
Version:7.x-2.x-dev» 7.x-1.x-dev
Component:Views Integration» Code

Move module

Title:Make Node Reference Relationships WorkMake Node Reference Relationships Work in Views
Status:Reviewed & tested by the community» Needs work

updating issue for References module.

works fine here

Works great here too. It's great to have this functionality back.

Works with the currently available downloads:
- Drupal 7 RC 1
- Views 7.x-3.x-dev (2010-Dec-4)

One caveat: The relationship did not appear until I cleared the Views' cache. Just in case anyone tried the patch and didn't see relationship, that is most likely the reason why.

Maybe this means the patch should include a hook_udate to clear cache ?

Maybe this means the patch should include a hook_udate to clear cache ?

Tough to say... with only ~50 sites reporting usage at this time, I think it is safe to add it in without the hook.

Component:Code» Code: node_reference

Categorizing.

Just to follow up, I've been using this module extensively in the last few days while building views. No problems other than that initial views cache snag that I can see.

Should we RBTC this?

Subscribing

As long you didn't changed the module name there is no reason why this shouldn't work anymore.

Oops, missed that one so far. Thanks mfer !

No time to look at this tonight, but I'll give it a try - or @fgm, if you beat me to it :-)

Status:Needs work» Needs review

Ideally, we'd need the same for user_reference.

same with #15

StatusFileSize
new1.46 KB

Here is a rerole

As I see it, commenting is a bit misleading: node_reference_field_views_data() is not an implementation of hook_views_data(): that role is fulfilled by field_views_data(), which in turn takes its data from implementations of hook_field_views_data() like node_reference_field_views_data() and implementations of hook_field_views_data_alter(), of which there is currently none in Views 3.

Another issue: on the one hand, having this function use field_views_field_default_views_data() means the module becomes dependent on field.views.inc, but it does not make sure that file is loaded. On the other hand, as an implementation of a hook defined in that same file, it will only ever be invoked if the module to which that file belongs is actually enabled, meaning the dependency will always be fulfilled unless some other module invokes that hook too, which I guess should not happen. I wonder what is the Drupal policy on such situations: should the dependency be recorded in the info file in some way ?

I applied patch #17, and it works fine. I use D7-rc3 and Views 7.x-3.x-dev (24-dec-2010).

StatusFileSize
new1.6 KB
PASSED: [[SimpleTest]]: [MySQL] 0 pass(es).
[ View ]

Comments updated

When I applied patch in #20, my test site went to white screen.
I'm using drupal core dev (dec-24) + views dev (dec-26) + references dev (dec-07).

Since around the 28th, I also just started having a white screen appear on every views edit screen that included a field reference. The white screen appears with all patches here: #0, #17 and #20.

Upon trying to add a reference to a new view, the follow error message appears:

An AJAX HTTP error occurred.
HTTP Result Code: 500
Debugging information follows.
Path: http://example.com/admin/structure/views/ajax/add-item/blog/default/relationship
StatusText: Internal Server Error

Coincidentally whatever happened does not affect the output on views that already have a field reference. Those views display the correct referenced information.

I'm using the D7 RC4 / Views dev (Jan-1) / References dev (Dec-07)

An update to my last post in #22...

With the latest build of Views, the white screen no longer appears and I can edit my view again. So whatever was a problem must have been with some of the views dev releases and not with this patch. Sorry for the false alarm!

jcarlson, thx for the heads up. I was really wondering what could have gone amiss.

StatusFileSize
new1.63 KB
PASSED: [[SimpleTest]]: [MySQL] 0 pass(es).
[ View ]

Added base field definition since I got a notice under some circumstances. Unfortunately I wasn't able to exactly define the conditions to trigger the issue.
Notice was thrown in views/modules/field/views_handler_field_field.inc line 57.
The code "causing" this notice was introduced by #1002744: Use entity_load for fieldapi field handlers.

Btw. besides this everything seems to work -> RTBC?.

Status:Needs review» Needs work

Peter,
I tested and used patch #17 on D7-rc3 and Views from around 25 december, and it worked fine. SO for me #17 was RTBC.

Today I upgraded to today's (7jan2010) -dev of Views, and got the same error (I think, I include the complete error below).
So, I have installed patch #25.
However, every view using node_reference, now gives empty fields!
My views-dev-version includes issue #102744.
I am still on D7RC3, could that be the problem?

This is the complete error message:
Notice: Undefined index: base field in views_handler_field_field->query() (line 57 of ...\modules\field\views_handler_field_field.inc).
Status messageDebug:
'Exception: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near \'AS node_, \'node\' AS field_data_field_site_ref_node_entity_type, \'node\' AS field_\' at line 1' in views_plugin_query_default->execute() (line 1314 of C:\Damp\Sites\drupal-7.0-rc3\sites\all\modules\views\plugins\views_plugin_query_default.inc).

Status:Needs work» Reviewed & tested by the community

#25 has worked great for us at Palantir with the latest D7.0.

johnv,
If you're using the latest views dev there's no need to patch it with #1002744: Use entity_load for fieldapi field handlers - this patch was integrated on the 5 / 6th January.
And atm. I can't imagine that using D7RC3 causes this problem.
Only things I can imagine are these:

  • The patch wasn't applied properly - just search in node_reference/node_reference.module for 'base field' => 'nid',. If you find it it's ok.
  • The views cache was not cleared after patching the node reference module
    • Could you check these two possibilities?

For what it's worth... my latest experience with these patches and views:

#17 and Views Jan 7 (with the views patch in #1002744) did not fix the #26 error for me (with clearing the cache).

#20 #25 and Views Jan 7 worked after I cleared the Views cache but not before.

Hats off to everyone for getting this great feature RTBC.

jcarlson34,
in you latest comment #29, you say:
>> #20 and Views Jan 7 worked after I cleared the Views cache but not before.
Do you mean #25 ? Because #17 and #20 are the same, apart from comments.

Peter,
Perhaps I must redefine my issue better:
The reference works, and I can show the ref'd node-title and even the 'rendered node' of the node-reference.
But if I add a field of the referenced node, this data does not get fetched. Or, if both content types contain the same field, the field-value is shown of the main-node, not of the referenced node.

Perhaps I made an error, please check below data.
Modules: D7.0 (5-jan-2011) + Views-dev (7-jan-2011) + References-dev (25-dec-2010)
Patches applied to node_reference.module: 962694#25 + 993394#5 + 1005364#4
Patches NOT applied to node_reference.module: 945004#10

Content Types: V (viewed) and R (referenced). Content type V has a node_reference-field 'R_ref' to R.

View-Relationships = Fields: field_R_ref - nid (no relationship)
View-Filter = Node: Type = V
View-Fields = Fields: field_r_ref field_r_ref (title) <== OK, Title is shown,
View-Fields = Fields: field_r_ref field_r_ref (rendered node) <== OK, complete node is shown in cell.
View-Fields = Fields: field_country field_text <== OK, node's field
View-Fields = (nid) Fields: field_country field_text. <== error, node's own field is shown, not referenced node.

Sorry if this turns out in a support request...

@johnv ah that's what I get for posting right after I get up. Yes I meant #25. Sorry about that.

I'll edit my post above to be correct.

Update on #31: I was doubting is it might be a Views-issue, so I made the same query with D6.20 + Views2 and with D6.20 + Views3. In both cases the resulted query is OK.

@johnv,
I've spent now some time trying to reproduce your issue.
My test view contains two relations based on node reference fields.
For each the base and the referenced contents I fetch at least 3 fields:
the node title (node), the node body (field) and another random field of the node type.
This means I've a "field" independent content (the node title), a "shared field" content (body) and the a node-type specific field content (random).
"Unfortunately" all this works perfectly.
I've definitely no idea what could cause the issue :|

@Peter, I have re-implemented some of the patches. Now it works fine, --> RTBC.
Thanks for your help, sorry for the inconvenience.

#25 worked for us also.
D7.0
references 7.x-2.x-dev
views 7.x-3.x-dev

Version:7.x-1.x-dev» 7.x-2.x-dev

Thanks for this patch, I was wondering why I wasn't seeing the node reference come up and I was starting to get a little worried :).

Worked for me with the same specs as the poster above me.

Sub

subscribe

Status:Reviewed & tested by the community» Active
StatusFileSize
new2.66 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch references_relationships-962694-42.patch.
[ View ]

Tested, tweaked a bit, and committed the attached patch.

Differences with #25:
- adds the relationship on both the 'current' and 'revision' field data tables, so that the relationship is also available on views listing 'node revisions'.
- adds a similar relationship for userref fields.

Leaving open, since there is still a little more work to do
- in D6, the relationship used a dedicated 'content_handler_relationship' handler, that added the ability to restrict the relationship on a given delta (for multiple fields)
- In addition to adding the relationship, CCK D6 did a little more massaging to the Views data :
replace the filter handler by an 'in' operator
use node.title (resp users.name) in argument summaries

Also, it seems that (Field API) fields (body, image...) added through the relationship are not displayed in the View (display the body of the referenced node).
Base properties (node title...) added through the relationship work OK, though.

[edit : created #1038240: Field API fields not displayed through a relationship about this]

subscribing

I have the same issue which is a pain with the project I'm working on now. Relationships for node title works great, relationships to images of the same node, not so much.

I can confirm #45 with the latest Reference module. Not sure if Reference or Field API is at fault.

Subscribe

Subscribe

re @ my own #43 : "Also, it seems that (Field API) fields (body, image...) added through the relationship are not displayed in the View (display the body of the referenced node)."

I was on crack (or rather I was tracking the wrong git branch). Works fine with current Views 7.x-3.x

Subscribe

Did patch #42 get committed to the latest dev version?

I see that the Jan 30 dev version of References now has the code from #42 included.

Everything works in Views. So is this issue RBTC and Fixed?

Issue stays open per yched's notes in #43:

Leaving open, since there is still a little more work to do
- in D6, the relationship used a dedicated 'content_handler_relationship' handler, that added the ability to restrict the relationship on a given delta (for multiple fields)
- In addition to adding the relationship, CCK D6 did a little more massaging to the Views data :
replace the filter handler by an 'in' operator
use node.title (resp users.name) in argument summaries

Thanks for that Les Lim. I reread #43 and apparently I missed this line somehow:

Tested, tweaked a bit, and committed the attached patch.

Was just confused that code made it in but it wasn't fixed yet. Makes much more sense now in context...

Assigned:Unassigned» Thoor

Subscribe

Status:Active» Fixed

Actually, let's handle the remaining tasks in separate threads. The 'relationship' part is fixed.

Status:Fixed» Active

Crap. The 'relationship' part is not completely over, we still need to add the dedicated handler.

For the other two points, I opened
#1046886: [release blocker] Use the 'many_to_one' views filter handler
#1046898: [release blocker] use node.title (resp users.name) in Views argument summaries

Title:Make Node Reference Relationships Work in Views[release blocker] Make Node Reference Relationships Work in Views
Assigned:Thoor» Unassigned

Thus, marking as release blocker.

@Thoor : addigning an issue to yourself means you intend to work on a patch :-). If that's the case, feel free to reassign.

My status is identical to comment 31: "The reference works, and I can show the ref'd node-title and even the 'rendered node' of the node-reference. But if I add a field of the referenced node, this data does not get fetched. Or, if both content types contain the same field, the field-value is shown of the main-node, not of the referenced node."

I'm using Views 7.x-3.0-alpha1 and Node Reference 7.x-2.x-dev (as released today) - no patches applied.

@hansfn: you should use the latest Views dev, not views-7.x-alpha1.

Thx, that solved it. This bug is fixed for me (but I guess I might need the "dedicated handler" even if I don't understand what it is).

Had the same prob as in #58/#31. Solved it for me, too. Thanks a lot!

subscribe

Status:Active» Needs review
StatusFileSize
new5.63 KB
PASSED: [[SimpleTest]]: [MySQL] 0 pass(es).
[ View ]

Attached patch adds the relationship handler - adds an option to select a delta to restrict the relationship.
Should be a no brainer, this is more or less directly copied from CCK D6. I'll try to test a little more extensively tomorrow, and will probably commit pretty soon.

Just like with #1046898: [release blocker] use node.title (resp users.name) in Views argument summaries, the views handler needs to be exposed by a wrapping module. Thus, patch introduces references.module.

Tested both noderef and userref, works fine.
I'll commit this tomorrow night if no one objects.

Status:Needs review» Fixed

Committed #63.

Hey,
I have just updated the Node Reference module and Views module (Views-7-3-dev) (before that I had 7th Feb dev-version and I don't quite remember what was the Node Reference), anyhow, before that I could fetch image fields from the referenced nodes, and now it returns empty image fields (while other fields work well).
I'm pretty new in issue tracking so if I won't switch to active.

Echo @Nikro's comments. In the referenced node in the view, image fields are showing up as blank, while others (e.g. title) are showing up as expected. This is my first time trying this, so I can't say whether it was working before or not.

I am using:
references.info,v 1.1.2.1 2011/02/15 21:11:52 yched Exp $ \ version = "7.x-2.x-dev" (no patches)
views.info,v 1.7.6.60 2011/01/05 21:34:52 dereine Exp $ \ version = "7.x-3.0-alpha1" (no patches)

I'll reply if I find a solution.

Thanks,
Dave

@DavidHadaller, please upgrade to latest Views-dev first; alpha-1 has to much open and already fixed issues.

Also, make sure you enabled the new 'references' module.

Status:Fixed» Closed (fixed)

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

sub

Thanks for the help! The part of my project that required node references is on hold for the moment, I'll report back if there is still a problem but I'm guessing the dev version of views will take care of it. Thanks!

Priority:Normal» Critical
Status:Closed (fixed)» Needs work

This does not work properly with the latest release of views.

When used as a relationship, it doesn't alter the output.

For example, I pass in a node id, and have a view that grabs all nodes (of the same type) that have this node id in a reference field. Rather than returning the list of nodes that reference this ID, it returns just the node with the ID passed in (as if the relationship weren't specified at all)

@willvincent : can you post an export of your view (in an attached .txt file) ?

I'll have to recreate it when I have time.. I've already dumped the DB and moved back to D6 for the time being. :\

Deadlines, ya know...

I'll see if I can get you something within the next day or so though.

subscribe

Category:bug» support

sub

I'm still having trouble showing an image field from a referenced node. Is this supposed to have been fixed yet? In my case I have a content type A that references content type B, which again refererences a content type C with an image, and I'm trying display that image in a custom view that lists entries of A. The image field from C appears in the "entity shortcut" help for rewriting, so it seems to figure out that it should be available through the relationships, but it never appears (it's treated as empty, according to my "text to display when empty" setting).

kjeldahl, please check if you have the same problem when you create a view with only B and C.
Also make sure that the 2nd relation B->C depends on the first one A-> B.

Thanks for responding. I redid everything again, verifying the relationship setup you mention, and suddenly everything works. I know I tried this earlier as well, so I would speculate that me upgrading everything - including Drupal 7 and the views module - to dev releases may have helped. Anyway, seems to work great now, thanks!

Status:Needs work» Fixed

OK, setting back to fixed for now, until someone can provide an actual view that doesn't work.

Status:Fixed» Closed (fixed)

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

I'm having the same 'no relationships in fields/filters' with Views 7.x-3.x-dev and References 7.x-2.x-dev.

Any advise is appreciated.