Hello,

I have a content type with a user reference field. I wish to make a View where content of this type is sorted by the user entered in the aforementioned user reference field, but this field is not available in the list of items available as Sort Criteria in Views. The user reference field is available for Fields and Filters in Views, just not for Sort Criteria. Is this a deliberate omission or have I missed something?

Thanks to all who assist.

Comments

petertj’s picture

I also encountered this problem, and with Node Reference fields too... so this may be a limitation of the referencing mechanism - either fundamental limit, or not yet implemented?

Possibly related issue - in table-formatted views, grouping by reference fields is broken - it creates a separate one-row table for every node in the view, regardless of the values in the reference field.

yched’s picture

Title: User reference field not available in Views Sort Criteria » Views sorting for userref / noderef
Status: Active » Closed (works as designed)

The only 'sort' that would be available would sort on the numerical user id (or the node id in case of a noderference field), which doesn't make much sense.

I do think that if you add a 'relationship' on the user field, you might be able to add a sort criteria on whatever user property. Haven't actually checked, though.

karens’s picture

Yes, adding a relationship is the answer. Once you add a relationship to the referenced node, you can add a sort for any field in the referenced node -- title or anything else that makes sense.

The possibly-related issue is not related and needs its own issue, Please open a new issue for the problem about grouping by reference fields with more details. It's not clear if you are having trouble with the grouping created by the option to 'group multiple values' in the field setting or by the new Views option to group values.

william_frane’s picture

Capital! Thanks for the assistance, everyone.

petertj’s picture

Thank you! Now using a relationship to the referenced node title. Makes perfect sense in retrospect... but it was not immediately clear why the "Sortable" option was missing in Basic Settings:Style:Table.

Might it be feasible to show an advanced help (?) link in place of the missing Sortable checkbox? And/or add an explanation to the existing Table output style and Sorts help pages. If it makes sense, feel free to point me to the right place to contribute on expanding the help, happy to do my part.

Found what was causing my grouping problem, happens when the "Link this field to its node" option is checked on a direct node reference. I'll look to see if that's already been reported under CCK, and post a new issue if needed.

Thanks for the great work, and great support!

yched’s picture

@Karen : Actually I wonder if noderef / userref fields should be proposed as 'Views fields' at all. All they do can be done via relationships, and so much more.

karens’s picture

Hmm... that's an interesting question. Maybe you're right, that never really occurred to me. Let's sleep on that idea :)

petertj’s picture

Ah, that makes sense... but please don't take away the Full Node display, which I have since used in another view.

I tried doing this using a relationship field, but it only appears to offer the Teaser, which cut off long descriptions 'cause we have other CCK fields at the top of the Project node.

Is there some other way to get that? Maybe Full Node could be added to the standard field options? Am I missing something?

karens’s picture

Status: Closed (works as designed) » Active

If the Full Node display isn't available for a relationship, that is probably a bug that needs to be fixed. I assume it would be a Views bug since I don't think there's anything we can do on the CCK side to set the relationship up differently.

Marking this back to active while we discuss.

petertj’s picture

I had previously come across an old dialog on this topic: http://drupal.org/node/70380
Seemed to reach a partial resolution there... moving node references into relationships might be the answer to that as well - worth linking these two topics?

biohabit’s picture

With regards to the tabular view, it appears at least with views 2.0 rc2 that you still can't sort on node reference fields. Is this possible?

yched’s picture

did you read comment #2 above ?

biohabit’s picture

Yes and no ability to have sortable node reference column emerged. I am using CCK rc7 and views rc2. I'm able to dynamically sort using the title and update date but nothing else.

karens’s picture

Status: Active » Fixed

Read #3, add a relationship to the view using the nodereference field. Probably make it required to be sure you only get nodes that have a related node. Then add the field you want to sort on as a sort, like the node title. Once you have added a relationship to the view, when you add a sort you'll see an option to use 'no relationship' to use the title of the original node or use the title of the related node, so choose the option to use the title of the referenced node.

You can do the same thing with the userreference field to show user fields.

arhak’s picture

What about a site like drupal.org which identifies the issues by nid?
whouldn't be useful sorting by nid? (with/without relationship)

arhak’s picture

@KarenS also when using table layout there is no need of any sort, rather sortable column are preferable, so after the relationship was created add the field and select the relationship
for instance:
a Project has the author user who created it, but also a userreference to a Project Manager
- to sort by author add a field User:author and 'no relationship'
- to sort by Project Manager add the SAME User:author BUT selecting the relationship previously created
Also note that any field can be added many times, each time using a different relationship (having an idea about SQL will help, so read the query and try to figure out the bijection between SQL and Views Control Panel)

Being an old SQL dog didn't figure it out the first time, because use to add the relationship expecting new field to become available, something like "User:author" & "User:author (field_project_manager)" making the difference between with/without relationship but as it didn't came up, never added the field again, so never saw the next screen asking for the relationship option (definitely this is an issue, either documentation or usability one)

moshe weitzman’s picture

@arhak - Views1 used to add many fields like that and the list of fields became unmanageable. The Views2 way of a smaller number of fields plus a relationship is far more usable.

As for documentation, this is well covered in the relationships page in the Advanced Help index. There is even an example regarding comments and users. No documentation issue either.

arhak’s picture

@moshe well... didn't know about Views1, but sounds fair, NEVERTHELESS a field could appear marked with a footnote (even better an advanced help link) stating that is a candidate field for several (or at least more than one) relationship alternatives.
As easy as: "User: name (*)" and a footnote/advanced help indicating why it's marked

As for documentation.. Are you sure? That was the first place where I returned when didn't figure it...
And yes you're right

When you add the "User: name" field, you will be presented with a select box. Either the node relationship or the user relationship must be selected, because there are two possible user names in the view to choose from.

But I read that (at least two times) and didn't catch the idea of you will be presented with a select box, always expected to be immediate while selecting the field, not in the next screen.
Certainly it's just a matter of being familiar with Views2, now was that my first need to relationship came up and I won't forget to RT!M.

But I insist on the documentation issue, since many relationships become implicit available it's kind of hard to figure out how does an SQL maps the UI, more when the UI comes through several steps of screens setup.

What I would expect the first time would be something like this

You will be taken through the fields you added one at a time. Click Update default display to go to each next field.

which advices me what will happen, so I remain calm knowing that missing config will be prompted afterwards.

Note: the advanced help of views is GREAT for newbies, for old Views1 users, and others, also I know the hard work it takes to create such a dedicated help. Moreover, I realize that the "Getting started" have been improved even more (I didn't saw it until right now)

karens’s picture

This is all Views documentation and the way that Views handles things. Doing anything about documentation or adding asterisks to field names or anything else is outside the scope of what CCK can do, that is all done in Views. CCK does not have any control over the Node: Title field, even for the title of a referenced node, Views handles that. CCK only controls the nodereference field itself. And the documentation you're referring to is all Views documentation.

So this issue has gone way beyond anything that CCK can or will do.

arhak’s picture

sorry, the second part of my comment #16 started a discussion out of topic
I just replied according to #17, didn't realize which module

Anonymous’s picture

Status: Fixed » Closed (fixed)

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