I am using Views 3.3 and the latest dev version of the References module. I have a view of type user and am trying to also bring in the most recently created node of type 'employee' created by those users in that same view.

I recently discovered the 'Representative node' relationship. When I use that, it works ok but gets me the latest node created by that user of any node type, not just the one I need. So I am trying the advanced 'Representative view' feature. I couldn't find much documentation about it but all views that I try (even fairly simple ones with no filters) fail. Do I need something special in those views, like an argument? Right now the simplest I set up is a representative view with a Content: nid field and sorted by created descending. The SQL that gets generated in the main view using the representative view is:

SELECT users.picture AS users_picture, users.uid AS uid, users.name AS users_name, users.mail AS users_mail, node_users.title AS node_users_title, node_users.nid AS node_users_nid
FROM
{users} users
LEFT JOIN {node} node_users ON (SELECT nodeINNER.nid AS nidINNER
FROM
{node} nodeINNER
LEFT JOIN {users} users_nodeINNER ON nodeINNER.uid = users_nodeINNER.uid
WHERE (( (users_nodeINNER.uid = users.uid ) ))
ORDER BY node_createdINNER. DESC
LIMIT 1 OFFSET 0) = node_users.nid
INNER JOIN {users_roles} users_roles ON users.uid = users_roles.uid
WHERE (( (users.status <> '0') AND (users_roles.rid IN ('3', '4', '5', '6')) ))

MySQL throws an error at this line:
ORDER BY node_createdINNER. DESC

As you can see it tries to order by 'node_createdINNER.' rather than by the (I think correct) nodeINNER.created.

I am not sure if this is a bug or I am incorrectly configuring the representative view, but it smells like a bug to me. :)

Comments

restyler’s picture

I can reproduce that with views 3.3. Any clue?

kasmel04’s picture

I'm seeing the same problem. I've tried both 3.3 and 3.x-dev with no luck on this.

kerberos’s picture

Yes, this was on Views 3.3. I'm using a PHP field from Views PHP with an extra query for each record for this as a work around, but it's not pretty. :)

jamix’s picture

Sounds very much like the namespacing problems I've had with views_handler_relationship_groupwise_max.inc. Please check if the patch in http://drupal.org/node/1417090#comment-7152112 works for you.

askibinski’s picture

I can confirm the patch at #35 in below issue fixes this one.
#1417090: Taxonomy term "Representative node" views with filters and sorts don't work

13rac1’s picture

Status: Active » Closed (duplicate)

The issue is different, but the cause is the same. Setting this to duplicate of #1417090: Taxonomy term "Representative node" views with filters and sorts don't work.

13rac1’s picture

Please RTBC the patch there.

dadderley’s picture

The patch @ #35 in https://www.drupal.org/node/1417090 fixed my specific issue for (7.x-3.7+36-dev).
Views 7.x-3.8 appears to have this patch and my issue has been solved.
Thank you