Closed vesper8 closed 4 years ago
Are you sure this works? I didn't think the API supports filtering by user.
Agreed, the SDK could definitely be improved. Only so many hours in the day...
actually.. you're right.. upon trying to make this function myself.. which would look like this:
/**
* @return \InvoiceNinja\Models\AbstractModel
*/
public static function findBy($where)
{
$url = static::getRoute();
$columns = array_keys($where);
$values = array_values($where);
for ($i = 0; $i < count($where) ; $i++) {
$url = sprintf("%s?{$columns[$i]}=%s", $url, $values[$i]);
}
$data = static::sendRequest($url);
$result = [];
foreach ($data as $item) {
$result[] = static::hydrate($item);
}
return $result;
}
// call like this
$tasks = Task::findBy([
'user_id' => 2,
]);
I realized that actually.. my above method doesn't work...
So there's no way to filter by anything other than client_id ? Well.. that's.. pretty lame
Will have to do the filtering on my side then.. which will become a problem when I end up with too many records
This sounds like it would be a fairly easy thing to add.. if there's willingness.. If I understand correctly, it's not so much the SDK that lacks flexibility but the API itself ? Well it's both but.. adding my above method to the SDK would only solve half the problem
Still the other half should be pretty simple to add too?
Ugh.. I see I can't even filter on my side since the user_id is not returned at all...
Feel free to create a PR (on the develop branch), here's the relevant code:
Actually, this change is trickier than it looks (due to multi-tenancy). We probably wouldn't be able to merge your PR. You'd need to copy how the client_id is handled. You may want to create an issue/feature request.
I guess this is possible since I just tried it, but I had to make this custom function which is just a replicate of the findByClientId
But instead of having to fork this sdk and start creating other functions.. shouldn't it be possible to use a flexible method to achieve this? Similar to a where() method
I would love to be able to use something like eloquent
This would become very useful once the number of tasks becomes too big.
In any case the skip/take limit would be a bonus, but at least being able to query by user_id without requiring a function dedicated to this would be a good improvement