Tried to run something like this:
user_relationships_load(array("approved" => 1, "user" => 1));
which returned no result, while user #1 should have 3 approved relationships with others.
Traced down to code and found that the query generated in user_relationships_load() was:
SELECT DISTINCT ur.rid,ur.*,urt.* FROM {user_relationships} ur INNER JOIN {user_relationship_types} urt USING ( rtid ) WHERE (urt.is_oneway <> 0 OR ur.approved <> 1 OR ur.requester_id < ur.requestee_id)
When I tried to run the query directly in MySQL, no result too.
But if I removed DISTINCT in query and ran it again in MySQL, where the query became:
SELECT ur.rid,ur.*,urt.* FROM {user_relationships} ur INNER JOIN {user_relationship_types} urt USING ( rtid ) WHERE (urt.is_oneway <> 0 OR ur.approved <> 1 OR ur.requester_id < ur.requestee_id)
It returned the 3 relationships of user #1 correctly.
I'm using MySQL 5.1.49 on Ubuntu 10.10.
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | remove-using-979680-9.patch | 702 bytes | mrf |
| #2 | 979680-remove-using-clause-sql-2.patch | 842 bytes | erikwebb |
Comments
Comment #1
benkewell commentedSorry the original query should be:
SELECT DISTINCT ur.rid,ur.*,urt.* FROM {user_relationships} ur INNER JOIN {user_relationship_types} urt USING ( rtid ) WHERE %s.%s = %d AND (ur.requester_id = %d OR ((ur.approved <> 1 OR urt.is_oneway <> 0) AND ur.requestee_id = %d))and the manual changed query should be:
SELECT ur.rid,ur.*,urt.* FROM {user_relationships} ur INNER JOIN {user_relationship_types} urt USING ( rtid ) WHERE %s.%s = %d AND (ur.requester_id = %d OR ((ur.approved <> 1 OR urt.is_oneway <> 0) AND ur.requestee_id = %d))I copied the wrong query above.
Comment #2
erikwebb commentedI am encountering the same issue. The query can be solved by removing
DISTINCTor changingUSING ( rtid )toON ur.rtid = urt.rtid. The second option is a more similar query. Although I can't explain the difference, this simple changes fixes the problem and leaves the SQL essentially the same.Here is my resulting query -
SELECT DISTINCT ur.rid,ur.*,urt.* FROM {user_relationships} ur INNER JOIN {user_relationship_types} urt ON ur.rtid = urt.rtid WHERE (ur.requester_id = %d OR ((ur.approved <> 1 OR urt.is_oneway <> 0) AND ur.requestee_id = %d)) AND %s.%s = %dI would definitely say this is critical. I wonder if this is an issue with an exact MySQL version (I am using 5.1.53).
Comment #3
berdirThe D7 has already changed to ON because USING is not supported by SelectQuery.
They only indication I could find is that USING might not use the correct table to join on under some circumstances.
Comment #4
ih2502mk commentedSee I've got two way relationship that needs approval (typical case like "friends" on every possible social network).
"Remove relationship" button at some point calls
And that leads to the query like this:
Part that goes after AND in WHERE clause returns FALSE actually on every operator:
And the relationship object is never created which makes impossible to remove a friend.
The condition
(urt.is_oneway <> 0 OR ur.approved <> 1 OR ur.requester_id < ur.requestee_id)comes from issue #479486: "/relationships" page doesn't show all users in relationship but it brakes work-flow of such a typical case like I described above (two way "friends" with approval).Comment #6
jim_at_miramontes commentedI got bit by this, too -- a call to user_relationships_load with a "user" argument failed to return anything, which thoroughly pooched my use of user_relationships_node_access. @erikwebb's patch in #2 worked fine (so far, anyway...); thanks much!
Comment #7
mrf commentedClosed #1282484: u_r_node_access blocking non-followers, but not allowing access to followers as a duplicate of this issue.
Looks like #2 just needs to be re-rolled git style for the testbot to pass.
Comment #8
mrf commentedHere is a re-roll the test bot should like.
ih2502mk just so I'm clear you began experiencing the problem you describe after applying this patch?
Comment #9
mrf commentedComment #10
berdirChange looks good and as I said before, that's what I already did in D7 anyway.
Comment #11
mrf commentedCommitted to 6.x-1.x