Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Is there going to be a relationship available for userreference fields in views with base 'user'?
If not already planned, I'd like to request this feature.
Comment | File | Size | Author |
---|---|---|---|
#14 | 375337.cck_.userref-backref-views.patch | 2.65 KB | joachim |
Comments
Comment #1
yched CreditAttribution: yched commentedEr, there should be already ?
Last time I checked, it worked well, I think...
Comment #2
casey CreditAttribution: casey commentedIn dev version I'm sure? I am using 6.x-2.1 and it's not available in that version, at least not for me...
Didn't check 6.x-2.x-dev really. But I thought, I mention it anyway.
But when it's in the dev version, you may close this issue.
Comment #3
yched CreditAttribution: yched commentedNo, it's in 2.1.
Of course, you need to be building a *node* view to have the relationship available (and you also need to actually have a userfield on one of your content types).
Other than that, I'm not sure why you would not see it...
Comment #4
casey CreditAttribution: casey commentedAh, I get it; what I means is:
I want the reverse relationship to be available. So we can create views that lists users that occur in userreference fields. this allows things like:
So that isn't possible yet? I think this would be a nice feature.
Comment #5
casey CreditAttribution: casey commentedSo this is a feature request again :)
Comment #6
casey CreditAttribution: casey commentedAdd to userreference_field_settings($op = 'views data') something like:
But now we don't have access to the node yet. I am not sure how to do this. Probably a new relationship handler is needed.
Comment #7
casey CreditAttribution: casey commentedUpdate:
It works when the following is added to userreference_field_settings($op = 'views data'):
Only issue is that the "userreference -> user" relationship is available also; not really an issue, but it might be confusing.
Hard to explain, but I think it should be clear.
Please integrate this feature. (There are others who are looking for this, e.g. http://acquia.com/node/17697)
Comment #8
casey CreditAttribution: casey commentedSomebody already had a look at this?
Comment #9
casey CreditAttribution: casey commentedComment #10
mrfelton CreditAttribution: mrfelton commentedCode in #7 works for me.
Comment #11
NikLP CreditAttribution: NikLP commentedSubscribing and hopefully trying this out.
Comment #12
NikLP CreditAttribution: NikLP commentedHave patched the module with the code provided. The relationship is indeed available to join the base user table to the node table via a user reference field. However, if you have more than one such field in existence, only the last created one appears as an available option in the "select a relationship handler"-type dialog in Views.
mrfelton and I proved this by deleting the last created reference field, and lo and behold a different field was available in its place.
At first we thought that there was a problem in the patch between single and multiple value fields, but this does not appear to be the case, so consider that bit tested.
Comment #13
joachim CreditAttribution: joachim commentedSubscribe.
Comment #14
joachim CreditAttribution: joachim commentedThe problem isn't that the code is wrong.
The problem is that the code returns an array like this for each field:
This is returned by userreference_field_settings($op = 'views data'), and all these arrays get merged to hand over to Views... and so the last field to return this clobbers all the others because they all have a 'user' key.
The fix is to change that array_merge to an array_merge_recursive.
Here's a patch which includes the code from #7 and the array fix.
I'm not sure why we're getting the relationships called "Content: FIELDNAME" -- as far as I can tell they're meaningless on a user view. I think that bit of the code needs a 'skip base' setting. The addition of the new code makes those appear whereas they didn't before, but the missing 'skip base' is a problem in existing code so out of the scope of this patch.
Comment #15
NikLP CreditAttribution: NikLP commentedTested this patch and it seems fine, I can now see all the user ref fields as relationships and arguments as expected. No clue about Jo's other comments regarding skip base, but that's another matter...
Comment #16
NikLP CreditAttribution: NikLP commentedComment #17
helmo CreditAttribution: helmo commentedWhile searching for something similar I found this issue and tried out the patch from #14.
It seems fine for making a reverse relationship list.
I did get stuck when I tried to add another cck filed linked to the node pulled in through the reverse reference. This gave me duplicate results, one of which correct. The distinct setting de-duplicates this, but does not return the right record.
But I think that's just asking for a messy join.
Comment #18
mr1 CreditAttribution: mr1 commentedTested the patch.. Works like a charm. Thanks!
Comment #19
NikLP CreditAttribution: NikLP commentedProbably needs re-rolling against the new userreference.module as CCK has been updated...?
EDIT: Actually no it doesn't. Obviously if the ur.module file has been updated, you need to reapply the patch, but I just applied it again with no problem, FYI.
Comment #20
casey CreditAttribution: casey commentedComment #21
pfaocleBit late I guess, but I'm currently using #14 on a site with cck 6.x-2.9. Working OK so far.
Comment #22
presleyd CreditAttribution: presleyd commentedUsing #14 now on CCK-6.x-3.0-alpha3 and it's working fine from what I can tell. Should this really be moved to References already? Granted I have some D7 sites and I'd like this functionality there but this patch seems like it could have been committed to CCK for D6 and then a new issue be created for References on D7? Perhaps I'm thinking that through clearly enough however.
Comment #23
yched CreditAttribution: yched commentedbackreference relationships have just been committed to References D7, in #1083902: Backreferencing (listing nodes that reference the target node). For D6, they are provided in the Reverse Node Reference module - http://drupal.org/project/reverse_node_reference.
Thus, marking as 'duplicate'
Comment #24
pvhee CreditAttribution: pvhee commentedReverse Node Reference only supports backreferences from node to node, and is clear about not including user->node backreferences (see #1139116: Could this support User reverse references?), so this issue is technically not a duplicate and I believe there is still a need for this and the patch from #14.
Comment #25
chingis CreditAttribution: chingis commentedI used patch #14 on 6.x-2.9 and it works fine, but I can't add fields from this back referenced content-type