I have created a custom flag, similar to the "watched list" on Ebay. The flag link is placed on the product page (print flag_create_link). I have cloned the default "view_bookmark_tab" view to create my own "watched list tab" in the user profile.

I have made the necessary changes to assure the relationships point to the correct flag and the current user. I attempted to test the view by flagging some products and then checking whether it displayed correctly in the newly created tab in my profile. The new tab is displayed but when I click on it I get a lengthy SQL error :

________________

* user warning: Column 'uid' in on clause is ambiguous query: SELECT COUNT(*) FROM (SELECT DISTINCT node.nid AS nid FROM node node INNER JOIN users users_flag_content ON uid = users_flag_content.uid INNER JOIN flag_content flag_content_node ON node.nid = flag_content_node.content_id AND (flag_content_node.fid = 2 AND flag_content_node.uid = 1) INNER JOIN users users ON node.uid = users.uid WHERE node.status <> 0 ) count_alias in C:\xampp\htdocs\drupal\sites\all\modules\views\includes\view.inc on line 745.
* user warning: Column 'uid' in on clause is ambiguous query: SELECT DISTINCT node.nid AS nid, node.type AS node_type, node.title AS node_title, users.name AS users_name, users.uid AS users_uid FROM node node INNER JOIN users users_flag_content ON uid = users_flag_content.uid INNER JOIN flag_content flag_content_node ON node.nid = flag_content_node.content_id AND (flag_content_node.fid = 2 AND flag_content_node.uid = 1) INNER JOIN users users ON node.uid = users.uid WHERE node.status <> 0 LIMIT 0, 25 in C:\xampp\htdocs\drupal\sites\all\modules\views\includes\view.inc on line 771.

_______________________

Underneath the error, "This user has not yet bookmarked any content" is displayed despite the fact that I have flagged relevant content.

I tried to remedy the solution by using some of the guides in the Flag module documentation, I also added and removed arguments, relationships, fields and filters. What seems to be a consistent issue is the fact that "uid" is always ambiguous, the rest of the SQL error changes based on what views options I have selected.

Any help is greatly appreciated.

CommentFileSizeAuthor
#11 flag_views_user_relationship.patch661 bytesquicksketch

Comments

mooffie’s picture

Status: Active » Postponed (maintainer needs more info)

Export your view and paste it here or on pastebin.com.

Stomper’s picture

$view = new view;
$view->name = 'flag_watchedproducts_tab';
$view->description = 'Provides a tab on all user\'s profile pages containing bookmarks for that user.';
$view->tag = 'flag, custom';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('relationships', array(
'uid' => array(
'label' => 'bookmarks_user',
'required' => 1,
'id' => 'uid',
'table' => 'flag_content',
'field' => 'uid',
'relationship' => 'flag_content_rel',
),
'flag_content_rel' => array(
'label' => 'Watched listings',
'required' => 1,
'flag' => 'watched_listings',
'user_scope' => 'current',
'id' => 'flag_content_rel',
'table' => 'node',
'field' => 'flag_content_rel',
'relationship' => 'none',
'override' => array(
'button' => 'Override',
),
),
));
$handler->override_option('fields', array(
'type' => array(
'id' => 'type',
'table' => 'node',
'field' => 'type',
'label' => 'Type',
),
'title' => array(
'id' => 'title',
'table' => 'node',
'field' => 'title',
'label' => 'Title',
'link_to_node' => 1,
),
'name' => array(
'label' => 'Author',
'link_to_user' => 1,
'id' => 'name',
'table' => 'users',
'field' => 'name',
),
));
$handler->override_option('arguments', array(
'uid' => array(
'default_action' => 'ignore',
'style_plugin' => 'default_summary',
'style_options' => array(),
'wildcard' => 'all',
'wildcard_substitution' => 'All',
'title' => '',
'breadcrumb' => '',
'default_argument_type' => 'fixed',
'default_argument' => '',
'validate_type' => 'none',
'validate_fail' => 'not found',
'break_phrase' => 0,
'not' => 0,
'id' => 'uid',
'table' => 'users',
'field' => 'uid',
'validate_user_argument_type' => 'uid',
'validate_user_roles' => array(
'2' => 0,
'5' => 0,
'4' => 0,
),
'override' => array(
'button' => 'Override',
),
'relationship' => 'uid',
'default_options_div_prefix' => '',
'default_argument_fixed' => '',
'default_argument_user' => 0,
'default_argument_php' => '',
'validate_argument_node_type' => array(
'blog' => 0,
'poll' => 0,
'product' => 0,
'rentals' => 0,
'services' => 0,
'items' => 0,
'forum' => 0,
'panel' => 0,
'answer' => 0,
'book' => 0,
'bookbase_book' => 0,
'bookbase_specifics' => 0,
'company' => 0,
'companypage' => 0,
'page' => 0,
'profile' => 0,
'question' => 0,
'sellerquestion' => 0,
'service_request' => 0,
'story' => 0,
'uprofile' => 0,
'user_profile' => 0,
'webform' => 0,
),
'validate_argument_node_access' => 0,
'validate_argument_nid_type' => 'nid',
'validate_argument_vocabulary' => array(
'1' => 0,
'3' => 0,
'11' => 0,
'10' => 0,
'5' => 0,
'2' => 0,
'4' => 0,
'6' => 0,
'7' => 0,
'12' => 0,
'9' => 0,
),
'validate_argument_type' => 'tid',
'validate_argument_transform' => 0,
'validate_user_restrict_roles' => 0,
'validate_argument_node_flag_name' => '*relationship*',
'validate_argument_node_flag_test' => 'flaggable',
'validate_argument_node_flag_id_type' => 'id',
'validate_argument_user_flag_name' => '*relationship*',
'validate_argument_user_flag_test' => 'flaggable',
'validate_argument_user_flag_id_type' => 'id',
'validate_argument_is_member' => 'OG_VIEWS_DO_NOT_VALIDATE_MEMBERSHIP',
'validate_argument_group_node_type' => array(
'company' => 0,
),
'validate_argument_php' => '',
),
));
$handler->override_option('filters', array(
'status' => array(
'operator' => '=',
'value' => 1,
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'status',
'table' => 'node',
'field' => 'status',
'relationship' => 'none',
),
));
$handler->override_option('access', array(
'type' => 'role',
'role' => array(
'2' => 2,
'5' => 5,
'4' => 4,
),
));
$handler->override_option('cache', array(
'type' => 'none',
));
$handler->override_option('title', 'My Watched Products');
$handler->override_option('empty', 'This user has not yet bookmarked any content.');
$handler->override_option('empty_format', '1');
$handler->override_option('items_per_page', '25');
$handler->override_option('use_pager', TRUE);
$handler->override_option('style_plugin', 'table');
$handler->override_option('style_options', array(
'grouping' => '',
'override' => FALSE,
'sticky' => 1,
'columns' => array(
'type' => 'type',
'title' => 'title',
'name' => 'name',
'comment_count' => 'comment_count',
'last_comment_timestamp' => 'last_comment_timestamp',
),
'default' => 'last_comment_timestamp',
'order' => 'desc',
'info' => array(
'type' => array(
'sortable' => TRUE,
),
'title' => array(
'sortable' => TRUE,
),
'name' => array(
'sortable' => TRUE,
),
'comment_count' => array(
'sortable' => TRUE,
),
'last_comment_timestamp' => array(
'sortable' => TRUE,
),
),
));
$handler = $view->new_display('page', 'Page', 'page');
$handler->override_option('path', 'user/%/watched');
$handler->override_option('menu', array(
'type' => 'tab',
'title' => 'Watched Listings',
'description' => '',
'weight' => '0',
'name' => 'navigation',
));
$handler->override_option('tab_options', array(
'type' => 'none',
'title' => NULL,
'description' => '',
'weight' => NULL,
'name' => 'navigation',
));

Stomper’s picture

Any luck with the finding issue using the views export?

Thanks again

Wooster’s picture

Version: 6.x-1.3 » 7.x-2.0-beta5

I am experiencing the same error. I however have not modified the default view, but I am running Drupal 7. The error persists regardless of which posted drupal 7 version of flags I use.

Error message:

Debug:

'Exception: SQLSTATE[23000]: Integrity constraint violation: 1052 Column \'uid\' in field list is ambiguous'
in views_plugin_query_default->execute() (line 1380 of /Users/01086520/Sites/drupal-7.2/sites/all/modules/views/plugins/views_plugin_query_default.inc).

Views output of user profile view causing error:

$view = new view;
$view->name = 'flag_bookmarks_tab';
$view->description = 'Provides a tab on all user\'s profile pages containing bookmarks for that user.';
$view->tag = 'flag';
$view->base_table = 'node';
$view->human_name = '';
$view->core = 0;
$view->api_version = '3.0-alpha1';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Defaults */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->display->display_options['title'] = 'User bookmarks';
$handler->display->display_options['access']['type'] = 'role';
$handler->display->display_options['access']['role'] = array(
  2 => 2,
);
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['query']['options']['query_comment'] = FALSE;
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '25';
$handler->display->display_options['style_plugin'] = 'table';
$handler->display->display_options['style_options']['columns'] = array(
  'type' => 'type',
  'title' => 'title',
  'name' => 'name',
  'comment_count' => 'comment_count',
  'last_comment_timestamp' => 'last_comment_timestamp',
);
$handler->display->display_options['style_options']['default'] = 'last_comment_timestamp';
$handler->display->display_options['style_options']['info'] = array(
  'type' => array(
    'sortable' => TRUE,
  ),
  'title' => array(
    'sortable' => TRUE,
  ),
  'name' => array(
    'sortable' => TRUE,
  ),
  'comment_count' => array(
    'sortable' => TRUE,
  ),
  'last_comment_timestamp' => array(
    'sortable' => TRUE,
  ),
);
$handler->display->display_options['style_options']['override'] = FALSE;
$handler->display->display_options['style_options']['sticky'] = 1;
$handler->display->display_options['style_options']['order'] = 'desc';
/* No results behavior: Global: Text area */
$handler->display->display_options['empty']['text']['id'] = 'area';
$handler->display->display_options['empty']['text']['table'] = 'views';
$handler->display->display_options['empty']['text']['field'] = 'area';
$handler->display->display_options['empty']['text']['empty'] = FALSE;
$handler->display->display_options['empty']['text']['content'] = 'This user has not yet bookmarked any content.';
$handler->display->display_options['empty']['text']['format'] = 'plain_text';
/* Relationship: Flags: bookmarks */
$handler->display->display_options['relationships']['flag_content_rel']['id'] = 'flag_content_rel';
$handler->display->display_options['relationships']['flag_content_rel']['table'] = 'node';
$handler->display->display_options['relationships']['flag_content_rel']['field'] = 'flag_content_rel';
$handler->display->display_options['relationships']['flag_content_rel']['label'] = 'bookmarks';
$handler->display->display_options['relationships']['flag_content_rel']['flag'] = 'bookmarks';
$handler->display->display_options['relationships']['flag_content_rel']['user_scope'] = 'any';
/* Relationship: Flags: User */
$handler->display->display_options['relationships']['uid']['id'] = 'uid';
$handler->display->display_options['relationships']['uid']['table'] = 'flag_content';
$handler->display->display_options['relationships']['uid']['field'] = 'uid';
$handler->display->display_options['relationships']['uid']['relationship'] = 'flag_content_rel';
$handler->display->display_options['relationships']['uid']['label'] = 'bookmarks_user';
$handler->display->display_options['relationships']['uid']['required'] = 1;
/* Field: Content: Type */
$handler->display->display_options['fields']['type']['id'] = 'type';
$handler->display->display_options['fields']['type']['table'] = 'node';
$handler->display->display_options['fields']['type']['field'] = 'type';
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['link_to_node'] = 1;
/* Field: User: Name */
$handler->display->display_options['fields']['name']['id'] = 'name';
$handler->display->display_options['fields']['name']['table'] = 'users';
$handler->display->display_options['fields']['name']['field'] = 'name';
$handler->display->display_options['fields']['name']['label'] = 'Author';
$handler->display->display_options['fields']['name']['link_to_user'] = 1;
/* Field: Content: Comment count */
$handler->display->display_options['fields']['comment_count']['id'] = 'comment_count';
$handler->display->display_options['fields']['comment_count']['table'] = 'node_comment_statistics';
$handler->display->display_options['fields']['comment_count']['field'] = 'comment_count';
$handler->display->display_options['fields']['comment_count']['label'] = 'Replies';
/* Field: Content: Last comment time */
$handler->display->display_options['fields']['last_comment_timestamp']['id'] = 'last_comment_timestamp';
$handler->display->display_options['fields']['last_comment_timestamp']['table'] = 'node_comment_statistics';
$handler->display->display_options['fields']['last_comment_timestamp']['field'] = 'last_comment_timestamp';
$handler->display->display_options['fields']['last_comment_timestamp']['label'] = 'Last Post';
/* Contextual filter: User: Uid */
$handler->display->display_options['arguments']['uid']['id'] = 'uid';
$handler->display->display_options['arguments']['uid']['table'] = 'users';
$handler->display->display_options['arguments']['uid']['field'] = 'uid';
$handler->display->display_options['arguments']['uid']['relationship'] = 'uid';
$handler->display->display_options['arguments']['uid']['default_action'] = 'default';
$handler->display->display_options['arguments']['uid']['exception']['title_enable'] = 1;
$handler->display->display_options['arguments']['uid']['title_enable'] = 1;
$handler->display->display_options['arguments']['uid']['title'] = '%1\'s bookmarks';
$handler->display->display_options['arguments']['uid']['default_argument_type'] = 'user';
$handler->display->display_options['arguments']['uid']['default_argument_options']['user'] = TRUE;
$handler->display->display_options['arguments']['uid']['default_argument_skip_url'] = 0;
$handler->display->display_options['arguments']['uid']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['uid']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['uid']['summary_options']['items_per_page'] = '25';
$handler->display->display_options['arguments']['uid']['specify_validation'] = 1;
$handler->display->display_options['arguments']['uid']['break_phrase'] = 0;
$handler->display->display_options['arguments']['uid']['not'] = 0;
/* Filter criterion: Content: Published */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = 1;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;

/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['path'] = 'user/%/bookmarks';
$handler->display->display_options['menu']['type'] = 'tab';
$handler->display->display_options['menu']['title'] = 'Bookmarks';
$handler->display->display_options['menu']['weight'] = '0';
wedge’s picture

Same issue here with 7.x-2.0-beta5 (running views 7.x-3.0-rc1 on postgresql). The generated query was this:

SELECT node.type AS node_type, node.title AS node_title, node.nid AS nid, node.language AS node_language, node_comment_statistics.comment_count AS node_comment_statistics_comment_count, node_comment_statistics.last_comment_timestamp AS node_comment_statistics_last_comment_timestamp, name AS name, uid AS uid
FROM 
{node} node
INNER JOIN {flag_content} flag_content_node ON node.nid = flag_content_node.content_id AND flag_content_node.fid = :views_join_condition_0
INNER JOIN {users} users_flag_content ON flag_content_node.uid = users_flag_content.uid
INNER JOIN {node_comment_statistics} node_comment_statistics ON node.nid = node_comment_statistics.nid
WHERE (( (node.status = :db_condition_placeholder_1) AND (users_flag_content.uid = :users_uid ) ))
ORDER BY node_comment_statistics_last_comment_timestamp DESC
LIMIT 25 OFFSET 0

I'm have no idea how views works yet but I guess that something could be wrong with how $arguments_tab is set up in flag.views_default.inc

mefisto75’s picture

same here. added a user. when hitting "bookmarks" tab get - 'Exception: SQLSTATE[23000]: Integrity constraint violation: 1052 Column \'uid\' in field list is ambiguous'

in views_plugin_query_default->execute() (line 1380 of /home/v/vmallru/streetvoices_ru/public_html/sites/all/modules/views/plugins/views_plugin_query_default.inc).

earthday47’s picture

I get this too. It definitely appears to be a collision with naming the relationship "uid".

Proposal:
Change the flag uid relationship id from 'uid' to 'flag_uid' or something similar?
(how to patch this?)

Files affected
flag.views_default.inc
flag_handler_relationship.inc
others?

------------

Workaround:
I worked around this by using the Views PHP Filter module. It's not very feature rich, but it gets the job done.

I removed all relationship and arguments from my view (it was a Profile attachment), and I added this code to the module's "Node -> Nod PHP Filter" filter:

$nids = array();
$uid = arg(1);
$query = db_query('SELECT content_id FROM {flag_content} WHERE uid = %s', array($uid));
while ($result = db_fetch_array($query)) {
  $nids[] = $result['content_id'];
}
return $nids;

This effectively bypasses all the views gobbledy-gook. I'd love to squash this bug, but this workaround meets my needs.

MGParisi’s picture

subscribe

MGParisi’s picture

Seems to be an issue with views and multiple blocks and content using user id. There is a fix that worked for me in the following node.
#1192962: Integrity constraint violation after update

wedge’s picture

@MGParisi thanks for the detective work. That worked for me too.

Fix: Edit the flag_bookmarks_tab view and click the "User: Name (Author)" field and then Apply

quicksketch’s picture

Status: Postponed (maintainer needs more info) » Fixed
StatusFileSize
new661 bytes

An alternative fix is adding the "Content: Author" relationship to the view and then making the "User: Name" field use that relationship. Previous versions of Views automatically added this relationship for you if you used the "User: Name" field (it automatically implied the node author). The latest version of Views doesn't have this automatic behavior. This patch re-adds the relationship manually to accomplish the previous functionality in a way that's backward-compatible with previous versions of Views (as "User: Name (Author)" is a newer addition).

Tested and applied to both 2.x branches for D6 and D7.

quicksketch’s picture

Title: user warning: Column 'uid' in on clause is ambiguous query... Flags Custom View profile tab » User warning: Column 'uid' in on clause is ambiguous query on Flag default views

Updating title.

mototribe’s picture

that fixed it for me (I changed the view manually)

Thanks Nate

UWE

Status: Fixed » Closed (fixed)

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