I'm trying to use the advertised ability of user_relationships_load to find a relationship created or updated within a range of times, and it doesn't seem to be working. Here's what's going on:
* I have an entry in {user_relationships} with, among other things, requester_id => 5 and updated_at => 1291018071.
* Following the documentation/comments in user_relationships_api.api.inc, I wrote the following call:
$theTest = user_relationships_load(array('requester_id' => 5, 'updated_at' => ">= 1290000000", 'updated_at' => "< 1300000000"));
* This should, I believe, return at least the entry mentioned above. Instead, an empty/null array comes back.
To try to get some idea of what's going on, I put a print_r on the value of $query on line 372 of user_relationships_api.api.inc. It produces the following:
Array
(
[query] => SELECT DISTINCT ur.rid,ur.*,urt.* FROM {user_relationships} ur INNER JOIN {user_relationship_types} urt USING ( rtid ) WHERE %s.%s = %d AND %s.%s < '%s'
[count] => SELECT COUNT(DISTINCT rid) AS count FROM {user_relationships} ur INNER JOIN {user_relationship_types} urt USING ( rtid ) WHERE %s.%s = %d AND %s.%s < '%s'
[arguments] => Array
(
[0] => ur
[1] => requester_id
[2] => 5
[3] => ur
[4] => updated_at
[5] =>
)
)
That empty value in position 5 of the final array looks suspicious to me, but I don't know the code enough to go much beyond that.
So: Am I doing something wrong (always a possibility) or is there a bug here?
Comment | File | Size | Author |
---|---|---|---|
#21 | user_relationship_load-dates-985672-21.patch | 812 bytes | sarci |
#9 | user_relationship_load-dates-985672-9.patch | 563 bytes | mrf |
#8 | user_relationship_load-dates-985672-8.patch | 719 bytes | mrf |
Comments
Comment #1
alex.k CreditAttribution: alex.k commentedLooking through the code, the problem seems to be in _user_relationship_process_query_argument() in the block starting at line 185:
$matches[3] may be a problem... basically it's not extracting your timestamp value from the regular expression. It may have to be matches[2], not [3].
Comment #2
alex.k CreditAttribution: alex.k commentedBy the way,
array('requester_id' => 5, 'updated_at' => ">= 1290000000", 'updated_at' => "< 1300000000")
has the same key updated_at for two values, hence the first of them is getting dropped.Comment #3
jim_at_miramontes CreditAttribution: jim_at_miramontes commentedI had the same thought, but all I was doing was repeating what was shown in the comments/documentation in user_relationships_api.api.inc (line 309):
Is this documentation incorrect? This is where I got the idea in the first place.
Just for fun, I tried:
I'm not sure if this was supposed to work, but it didn't. The value of $query was:
I'm currently handling my problem by doing a direct db_query into {user_relationships}, but if there's a way to do this with user_relationships_load(), I'd probably prefer it. On the other hand, if this isn't supposed to work, the documentation ought to be corrected to reflect the reality of the code.
Comment #4
alex.k CreditAttribution: alex.k commentedNo, you are right that it's both a bug and incorrect documentation. I think that nobody ever hit that use case before. And I never noticed it was written this way :)
Replacing $matches[3] with $matches[2] might help if you want to give that a try. In any case, for your situation a direct query is better.
Comment #5
mrf CreditAttribution: mrf commentedTagging for better tracking.
Comment #6
mrf CreditAttribution: mrf commentedAnd more tagging.
Comment #7
mrf CreditAttribution: mrf commentedClosed #988322: user_relationships_load not processing arguments with operators correctly, no results returned as a duplicate of this issue, but remember to give smthomas credit for his patch.
Comment #8
mrf CreditAttribution: mrf commentedHere's a patch for this, I just want to see what the bot has to say about this.
There should really be new tests included for testing any date-based parameters sent to user_relationships_load.
Comment #9
mrf CreditAttribution: mrf commentedOk, time time to stop for the day I think.
Here's another go at that one line patch...
Comment #10
mrf CreditAttribution: mrf commentedComment #12
mrf CreditAttribution: mrf commented#9: user_relationship_load-dates-985672-9.patch queued for re-testing.
Comment #14
mrf CreditAttribution: mrf commented#9: user_relationship_load-dates-985672-9.patch queued for re-testing.
Comment #15
mrf CreditAttribution: mrf commentedFixed in 6.x-dev see http://drupalcode.org/project/user_relationships.git/commit/08e15a2
Moving to 7.x to confirm it is fixed there as well.
Comment #16
BerdirI'm actually not sure if still support this syntax. Might need to be re-added. Although I'd prefer to build this on top of the DBTNG conditions API instead of strings like that.
Comment #18
sarci CreditAttribution: sarci commentedAttached patch for D7.
Comment #19
sarci CreditAttribution: sarci commentedRe-attached patch for D7 (removed unnecessary row).
Comment #20
sarci CreditAttribution: sarci commentedRe-attached patch for D7 (added necessary row).
Comment #21
sarci CreditAttribution: sarci commentedD7 patch with fix on array value.