V
V
Vladimir Golub2018-02-18 16:24:40
PHP
Vladimir Golub, 2018-02-18 16:24:40

How to output related table in JSON?

I'm using this API: https://github.com/alixaxel/ArrestDB I'm
using a table query, but it's linked to another table. How to get a json object instead of an external record id?
Now like this:

{
    "id": 1,
    "name": "Тестовая запись",
    "id_tabletest": 1
  },
  {
    "id": 2,
    "name": "Тестовая запись",
    "id_tabletest": 2
  }

Necessary:
{
    "id": 1,
    "name": "Тестовая запись",
    "id_tabletest": {
   "id": 1,
    "name": "Тестовая запись",
}
  },
  {
    "id": 2,
    "name": "Тестовая запись",
    "id_tabletest": {
    "id": 1,
    "name": "Тестовая запись",
}
  }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Kuznetsov, 2018-02-18
@RazerVG

Judging by what I saw in this library - no way. More precisely, you can make a call to the view through it, where you can use json_agg ( https://postgrespro.ru/docs/postgrespro/10/functio... ) to convert what you need into json.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question