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
Implement attributesToRetrieve for getObjects method #273
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -210,12 +210,14 @@ public function getObject($objectID, $attributesToRetrieve = null) | |
* Get several objects from this index. | ||
* | ||
* @param array $objectIDs the array of unique identifier of objects to retrieve | ||
* @param $attributesToRetrieve (optional) if set, contains the list of attributes to retrieve as a string | ||
* separated by "," | ||
* | ||
* @return mixed | ||
* | ||
* @throws \Exception | ||
*/ | ||
public function getObjects($objectIDs) | ||
public function getObjects($objectIDs, $attributesToRetrieve = null) | ||
{ | ||
if ($objectIDs == null) { | ||
throw new \Exception('No list of objectID provided'); | ||
|
@@ -224,6 +226,11 @@ public function getObjects($objectIDs) | |
$requests = array(); | ||
foreach ($objectIDs as $object) { | ||
$req = array('indexName' => $this->indexName, 'objectID' => $object); | ||
|
||
if ($attributesToRetrieve) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will fail if empty array is provided. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's correct behavior. Empty array = all attributes are fetched There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is not the current behaviour. Empty string returns only objectIDs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's the API behavior for |
||
$req['attributesToRetrieve'] = $attributesToRetrieve; | ||
} | ||
|
||
array_push($requests, $req); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should ask for an array of strings like we do for the other methods.
The documentation is bad for some of the other methods, we say we expect comma separated values where we are actually accepting arrays.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to be consistent with
getObject
method where we take comma-separated string.Definitely not something I'd approve and I'd definitely rather accept
array
, but for me consistency has higher priority right now.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Arg, I just tested and it doesn't work with an array in the 'getObject' method.
I would:
getObject
andgetObjects
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, can you review @rayrutjes?