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.
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | flag_views_user_relationship.patch | 661 bytes | quicksketch |
Comments
Comment #1
mooffie commentedExport your view and paste it here or on pastebin.com.
Comment #2
Stomper commented$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',
));
Comment #3
Stomper commentedAny luck with the finding issue using the views export?
Thanks again
Comment #4
Wooster commentedI 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:
Comment #5
wedge commentedSame issue here with 7.x-2.0-beta5 (running views 7.x-3.0-rc1 on postgresql). The generated query was this:
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
Comment #6
mefisto75 commentedsame 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).
Comment #7
earthday47I 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:
This effectively bypasses all the views gobbledy-gook. I'd love to squash this bug, but this workaround meets my needs.
Comment #8
MGParisi commentedsubscribe
Comment #9
MGParisi commentedSeems 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
Comment #10
wedge commented@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
Comment #11
quicksketchAn 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.
Comment #12
quicksketchUpdating title.
Comment #13
mototribe commentedthat fixed it for me (I changed the view manually)
Thanks Nate
UWE