saintsystems / odata-client-php

OData Client Library for PHP
MIT License
141 stars 103 forks source link

Get a specific item from a collection by ID (multi-part key) #111

Closed wabuMike closed 1 year ago

wabuMike commented 1 year ago

The wiki says that getting a specific item by ID works with find: $person = $odataClient->from('People')->find('russellwhyte');

OData supports multi-part keys. This is also implemented (https://github.com/saintsystems/odata-client-php/blob/2474e87d30def0a3a985abc32af6a1d08cb6f83f/src/Query/Grammar.php#L160) and works great.

It took me a while to find that, which is why it would be great if we can document that. There are two documentations I recommend to improve:

  1. Add alternative parameter data type "array" to https://github.com/saintsystems/odata-client-php/blob/2474e87d30def0a3a985abc32af6a1d08cb6f83f/src/Query/Builder.php#L767 . Like @param int|array $id
  2. Add an example like the following to https://github.com/saintsystems/odata-client-php/wiki/Example-Calls :

    ##Get a specific item from a collection by multi-part ID
    
    // Or retrieve a specific entity by the Entity multi-part ID/Key
    // Issues an HTTP GET request to http://services.odata.org/V4/TripPinService/People('russellwhyte')
    $person = $odataClient->from('People')->find(['username' => 'russellwhyte', 'userid' => '1']);
    echo "Hello, I am $person->FirstName ";
anderly commented 1 year ago

Closed by 08a00d3 and updated wiki example calls.