1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 20:22:42 +01:00

Add eager loading to API tasks

This commit is contained in:
Hillel Coren 2016-11-16 13:12:10 +02:00
parent 04bbf1b2ae
commit de2825750d
2 changed files with 4 additions and 8 deletions

View File

@ -41,6 +41,7 @@ class TaskApiController extends BaseAPIController
{ {
$tasks = Task::scope() $tasks = Task::scope()
->withTrashed() ->withTrashed()
->with('client', 'invoice')
->orderBy('created_at', 'desc'); ->orderBy('created_at', 'desc');
return $this->listResponse($tasks); return $this->listResponse($tasks);

View File

@ -38,19 +38,14 @@ class TaskTransformer extends EntityTransformer
public function transform(Task $task) public function transform(Task $task)
{ {
if($task->invoice)
$invoiceId = $task->invoice->public_id;
else
$invoiceId = null;
return array_merge($this->getDefaults($task), [ return array_merge($this->getDefaults($task), [
'id' => (int) $task->public_id, 'id' => (int) $task->public_id,
'description' => $task->description, 'description' => $task->description,
'duration' => $task->getDuration(), 'duration' => $task->getDuration(),
'updated_at' => (int) $this->getTimestamp($task->updated_at), 'updated_at' => (int) $this->getTimestamp($task->updated_at),
'archived_at' => (int) $this->getTimestamp($task->deleted_at), 'archived_at' => (int) $this->getTimestamp($task->deleted_at),
'invoice_id' => $invoiceId, 'invoice_id' => $task->invoice ? (int) $task->invoice->public_id : false,
'client_id' => (int) $task->client->public_id, 'client_id' => $task->client ? (int) $task->client->public_id : false,
'is_deleted' => (bool) $task->is_deleted, 'is_deleted' => (bool) $task->is_deleted,
'time_log' => $task->time_log, 'time_log' => $task->time_log,
'is_running' => (bool) $task->is_running, 'is_running' => (bool) $task->is_running,