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.
The node reference field is not sortable in Views. I think that content.module might need some tweaking to make that happen, because the basis for that source would be the referenced node's title, not nid.
Same for user reference.
Comment | File | Size | Author |
---|---|---|---|
#20 | cck_nodereference-1.6_sort.patch | 13.51 KB | xxvelcrar |
#15 | nodereference_userreference_patches.tar__0.gz | 1.5 KB | dan3h |
#14 | nodereference_userreference_patches.tar_.gz | 1.5 KB | dan3h |
#3 | nodereference.module_14.patch | 13.32 KB | KarenS |
Comments
Comment #1
KarenS CreditAttribution: KarenS commentedThis is still an issue and we really should get this working, so I'm bumping it.
Comment #2
appel CreditAttribution: appel commentedAgreed, this should be fixed imho. I'm having a hard time explaining to my boss why the table can't be sorted by the referenced 'company' field, while at the same time it can be sorted by less important fields.
Comment #3
KarenS CreditAttribution: KarenS commentedHere's my Christmas present to everyone -- I think I have this working. I've created a patch that joins in another copy of the node table for each nodereference field and gives you all the standard node fields for the referenced node -- title, creation date, type, body, whatever field you want to pick. If you want a sortable field, use the referenced node's title field instead of the standard nodereference field. You only need the title field to do sorting, but I thought it might be useful to add the other fields in.
I'm sure this needs debugging, but here it is (the patch is for 4.7, but should work the same in 5.x).
The downside is that it adds a lot of fields to the list. If you only have one or two nodereference fields it's not too bad. If you have a lot, it might be. At least all the fields for each nodereference sort together in a group. We could get rid of some of the referenced fields but I can think of lots of use cases where you might want the other fields, so for now at least I put them all in.
Comment #4
KarenS CreditAttribution: KarenS commentedI guess I'll assign myself :-)
Comment #5
moshe weitzman CreditAttribution: moshe weitzman commentedthis is working for me as designed! i hear you about field creep, but i think this is reasonable for now.
i couldn't get the node ref argument to work. you should pass a single nid? if so, the name of the node ref argument should end in 'nid' i think. the help text for this argument isn't so helpful. i don't think this argument is added by this patch though. i'm not sure where it is defined.
i have a related feature request, but i'll save that for another day and another issue. you nailed this one.
BTW, all i did to get this looking right on 5.0 is replace %name with @name.
Comment #6
moshe weitzman CreditAttribution: moshe weitzman commentedThis looks good for Sorts. but for Fields, I think it would be even better to implement "second" idea at http://drupal.org/node/91792. the fields implemention here is a subset of that, if I am grokking this properly.
Comment #7
KarenS CreditAttribution: KarenS commented@moshe, The reason for including fields as well as sorts here is that you need the fields set up this way to do table sorts, the sort fields won't work for that. This is a really simple, lightweight solution that makes it possible to sort and filter on basic node info for the referenced nodes. The link you refer to and the solution you mention there is going to be much more complicated. It's theoretically doable, but there are a number of hurdles to getting it working. So I see this as a simple 1.1 method for getting this functionality working, and the ideas in http://drupal.org/node/91792 are probably not going to get solved until the next version (or at least the next release).
And this patch does nothing with arguments, so that is another issue :-)
I still need to try all these fields and filters out. I just brought in all the fields and filters that are already defined for nodes, but some of them may not work right or make sense for referenced nodes (like the node: distinct filter). So we could hack some of them out and reduce the size of the list.
Comment #8
maherg CreditAttribution: maherg commentedThe referenced node's link is pointing to the actual row node returned from the views query.
Is anyone experiencing this too ?
Comment #9
mcreature CreditAttribution: mcreature commentedSubscribing
+1 Sounds very cool
Comment #10
biohabit CreditAttribution: biohabit commentedSubscribing
Comment #11
appel CreditAttribution: appel commentedSubscribing.
Comment #12
biohabit CreditAttribution: biohabit commentedHmm, the version 14 patch isn't working with CCK 1.5 and my stock versions of 1.5 don't appear to allow sorting on nodereference columns. Will future versions of this patch get incorporated into CCK?
Comment #13
joshk CreditAttribution: joshk commented+1 for this functionality; I'll see if I can roll a new patch for 5.x-1.5
Comment #14
dan3h CreditAttribution: dan3h commentedI have fixed a bug in this, and added a feature:
Bug fixed: Links went to wrong node. If you added a field of type "@name Referenced Node: Title", the clicking the link took you to the referring node, not the referenced node. That is fixed here, in
nodereference.patch
. (Note that this is a patch on top the the existing patch, provided by Karen, above in this thread.)Feature added: Usernames are clickable. I basically cloned for users what Karen had done for nodes, but pared way back (ie. just added one field-- no sorts or filters.) This is done in
userreference.patch
.I am using:
Drupal 5.1
CCK "5--1.3"
Views 5.x-1.6-beta5
BTW, this is my first-ever attempted patch-submission to any project. I hope it is in a format that is useful-- please let me know if not.
Comment #15
dan3h CreditAttribution: dan3h commentedOops, filename in attachment on previous posting got mangled a bit. Here it is again.
Comment #16
dan3h CreditAttribution: dan3h commentedOh, yikes-- it's even more mangled now. Please fix the filename to ".tar.gz" before opening.
Comment #17
discursives CreditAttribution: discursives commented+1
Comment #18
webchickThanks, dan3h for taking this up again. However...
a) Please don't upload .tar.gz/.zip/etc. files... the form shouldn't let you upload those 'by design'... cos people have no idea what they're getting until they've downloaded it.
b) Please either open a separate issue for making userreference fields sortable in Views, and put the userreference patch there, or else roll both changes into a single patch. I'm not sure if they belong together (since the changes are similar in each module) or if they belong as separate issues (because they're about two different modules), but keeping track of two patches in the same issue is a bit confusing. :)
Will try and test this later though; looks like a nice improvement!
Comment #19
wylbur CreditAttribution: wylbur commentedIs this still alive, it looks promising.
Comment #20
xxvelcrar CreditAttribution: xxvelcrar commentedI've attached that combines KarenS and dan3h's contributions to the nodereference module and updated it to work with CCK 1.6.
Unfortunately, this patch only works with a few select fields. I do not yet(!) know enough about Drupal to make it work with any field and welcome any assistance on that part :-)
Comment #21
tsega CreditAttribution: tsega commentedThis has been a great help! Now I can see some of the referenced fields as view filters, great! One more thing though I need to expose the none standard field types of the referenced node type, meaning the once that were created using CCK as view filters. How do I do that? Here's the code I believe that does it but it doesn't work for the field type I've added, i.e. the field_accessability. Need help please!
It seems like from the patch provided by dan3h, in the fields array you just add all the fields to be provided as filters, now I believe the problem I'm facing is giving the handler for my field. Please help me to solve this!
Comment #22
lelizondo CreditAttribution: lelizondo commentedI have been looking for something like this and this patch works great, but I need some other fields, the ones I create, not only the Title, ID, Created time, updated time....
I've found some other patches for the nodereference module (including the ones in this post) but for some reason the only one I can patch it's this one, the cck_nodereference-1.6_sort.patch, so I don't really know if there's another patch that does what I need.
Anyway, why can I apply this patch but not the other ones (always get Hunk Failed errors)? am I doing something wrong?
Thanks in advance.
Luis
Comment #23
llribas CreditAttribution: llribas commentedHi,
I need to order by title of referenced node, and I found this patch that looks the solution.
I have:
I downloaded the patch cck_nodereference-1.6_sort.patch, and applied succesfully, but no new options appears in "fields", "filters" or "Sort Criteria" in Views as I expected. I want the "Sort Criteria" -> "Referenced Node: Title".
Do I need to make something more before?
Is drupal 5.3 the problem?
Do I need to change %name for @name as mentioned above?
Getting this functionality working would be rewarding for me!
thx
Lluís
Comment #24
llribas CreditAttribution: llribas commentedForget this post... now it works... is it possible I must "Clear views cache" before the new options appear after applying the patch?? it looks like this, or I don't understand.
Comment #25
butler CreditAttribution: butler commentedSomething funky with this patch:
cck_noderefe…1.6_sort.patch
... please see issue I created here:
http://drupal.org/node/237855
Thanks...
Comment #26
lelizondo CreditAttribution: lelizondo commentedTo show a non-standard node field from a node reference in a view I had to add manually every single field, maybe this is not elegant but it works.
I created 2 content types:
1. Member. With fields like first name, last name and a node reference field 'event'
2. Event. Just a name and a date field 'field_m_date'
You could show in a view the Member First Name, Last Name and the Event which is a Node Reference to Event, but you can't show the Event's date.
To do this and thanks to the patch subbmitted by xxvelcrar in comment 20 I had to do this:
The most important thing to understand is how to create the neccesary joins (see http://drupal.org/node/99564) in my case, I had 3 related tables, node content_type_member and
content_type_event. content_type_event joins like this:
content_type_event.nid = content_type_member.field_m_event_nid
and content_type_member joins like this:
content_type_member.nid = node.nid
I hope someone with more experience could clean this code to have a more elegant solution, perhaps a more general solution. I understand that this is included in Views 2 and it works great but I had to make it work for drupal 5.x
Two more things, maybe they are related to each other.
After I created my view I found out that using views_handler_field_dates as a handler for the dates would show the date 12/31/1969 7:33 for every record I don't know why but I found an excelent solution adding one more function:
Thanks to westwesterson in http://drupal.org/node/147563 for that.
After I changed the handler views_handler_field_dates to views_handler_field_dates_iso everything works fine, BUT (there's always a but) I can't filter (I know the code I'm posting doesn't include filters) using the date and the date field shows like this: 2008-05-10T00:00:00. I don't know how to remove the T00:00:00 and could someone please confirm if this is why I can't filter? This is actually the real date of the event so that's ok except for the T00:00:00
Thanks
Luis
Comment #27
lelizondo CreditAttribution: lelizondo commentedI solved the issues I had, see this link to see how I did it: http://drupal.org/node/261408. However I must insist that I haven't found a general solution, maybe this is possible only with views 2, but I'm using 5.x and this is working for me.
Comment #28
lelizondo CreditAttribution: lelizondo commentedThere is a great solution for this using computed field:
http://drupal.org/node/290443
Comment #29
KarenS CreditAttribution: KarenS commentedClosing old issues. None of us is using the D5 version any more, so hard to provide any support. Sorry.