I'm trying to use this relationship to show the most recent blog post for a list of users. However, when I do this I get the following error:
Notice: Undefined offset: 1 in views_handler_relationship_groupwise_max->left_query() (line 282 of /Users/matt/Sites/ob/sites/all/modules/contrib/views/handlers/views_handler_relationship_groupwise_max.inc).
along with:
'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 \'DESC
LIMIT 1 OFFSET 0) = node_users.nid
WHERE (( (node_users.status = \'1\') AND (\' at line 3'
in views_plugin_query_default->execute() (line 1386 of /Users/matt/Sites/ob/sites/all/modules/contrib/views/plugins/views_plugin_query_default.inc).
I only get this when I use a view to build the subquery. After looking into it, I see that the order section in the subquery never has a table assigned, and the field is also aliased by the time we namespace the order query. This is a problem on two levels, first it doesn't build the fieldname right because the field coming out of getOrderBy isn't prefixed with a table alias. Also, since the order field gets removed from the query above, the aliased field name doesn't work because that field isn't declared in the query.
My probably overly simplistic solution is to cache the fieldnames in the query before we trim it down to just ID, so that later on we can figure out which field we really are sorting on, so we can correctly apply the namespace and get the query to work.
This is against -dev as of today, so hopefully I'm not missing something obvious that made this unnecessary.
Patch attached.
| Comment | File | Size | Author |
|---|---|---|---|
| views_handler_relationship_groupwise_max.inc_.patch | 1.8 KB | stockliasteroid |
Comments
Comment #1
dawehnerUpdate status. Please always take sure that you set an issue to needs review, so people will earlier see your patch. Thanks!
Here are some unneeded whitespaces added. TIP: use dreditor, the aweseome way to review patches.
In drupal you use strpos as it's a bit faster though you have to write strpos() !== FALSE
Can't you simple use $field_data = $fields_original[$order_key]; and drop the second foreach here?
The drupal code style adds a new line for the else.
Comment #2
jamix commentedThe fixes in http://drupal.org/node/1417090#comment-7152112 address what's suggested here, among other changes. Should this one be marked as a duplicate?
Comment #3
dawehnerYeah marking that as a duplicate is a good idea.
Thanks for posting here!