Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error matching __key__ in GQL query #98

Open
ajck opened this issue Mar 8, 2016 · 2 comments
Open

Error matching __key__ in GQL query #98

ajck opened this issue Mar 8, 2016 · 2 comments

Comments

@ajck
Copy link

ajck commented Mar 8, 2016

This is a failure with my GQL usage rather than php-gds I think, but I'm getting the error:
"__key__ filter value must be a Key" in my php logs when I do the following query:

$user_obj = $obj_store->query("SELECT * FROM Users WHERE __key__ = @userid", ['userid' => $userid])->fetchOne();

where $userid is the Datastore-assigned numeric key for that particular user from an earlier GQL query which I obtain with getKeyId() and is then stored in the PHP $_SESSION.

I tried changing the query to:

$user_obj = $obj_store->query("SELECT * FROM Users WHERE __key__ = KEY(Users, ".$userid.")");

but got the error:
"Argument 1 passed to GDS\Gateway::putMulti() must be of the type array, object given"

Any suggestions much appreciated!

Also, I'm not clear on when I should use (in a WHERE clause): __key__ = KEY(Store, item-to-match) vs. __key__ = @param", ['param'] => $item-to-match

Many thanks!

@ajck
Copy link
Author

ajck commented Mar 9, 2016

OK, after quite a bit more rooting around in the source code and examples I discovered I should actually be using $user_obj = $obj_store->fetchById($userid);

So just wanted to clarify my 2nd Q if poss! I'm not clear on when I should use (in a WHERE clause): __key__ = KEY(Store, item-to-match) vs. __key__ = @param", ['param'] => $item-to-match

Thanks!

@tomwalder
Copy link
Owner

Hi there.

Keys are "special" in Datastore (I think you may have discovered this from your SO thread).

My library lets you pass in an Entity as a parameter for binding and automatically turns it into the KEY() syntax.

Which means (theoretically) you are less likely to get GQL errors, escaping issues etc. Also it should work more easily for nested hierarchies etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants