1

这是我的代码查询

我只想从每个表中获取一些特定字段:

 const project = await Project.query()
      .where("user_id", user_id)
      .where('id', project_id)
      .with('items.file.sheets.markup.comment.attachment').first()

但我得到这个回应有很多额外的领域

"status": true,
    "message": "Here is detail of Your Project",
    "data": {
        "id": 1,
        "name": "Spacey",
        "description": "222 please change some points",
        "created_at": "2021-03-24 17:18:56",
        "updated_at": "2021-03-24 19:12:09",
        "deleted_at": null,
        "items": [
            {
                "id": 1,
                "project_id": 1,
                "assignee_id": 1,
                "status": null,
                "type": "markup",
                "description": "my  ",
                "version": 4,
                "visibility": "1",
                "due_date": "2019-12-31",
                "priority": "high",
                "resolved_on": null,
                "created_by": 2,
                "resolved_by": null,
                "updated_by": null,
                "created_at": "2021-03-24 17:19:02",
                "updated_at": "2021-03-24 17:19:02",
                "deleted_at": null,
                "file": [
                    {
                        "id": 1,
                        "actual_name": "10Feb2021.pdf",
                        "original_ext": "pdf",
                        "random_name": "1616588342707_8063",
                        "original_local_path": "files/2/1/1/1616588342707_8063.pdf",
                        "image_url": "https://resolve-dev-backend.s3.us-east- "
                        "media_type": "profile",
                        "item_id": 1,
                        "user_id": 2,
                        "created_at": "2021-03-24 17:19:05",
                        "updated_at": "2021-03-24 17:19:05",
                        "created_by": 2,
                        "updated_by": null,
                        "deleted_at": null,
                        "sheets": [
                            {
                                "id": 1,
                                "actual_name": "convertpdftojpg.png",
                                "original_ext": "png",
                                "random_name": "1616588346705_117",
                                "original_local_path": "sheets/2/1/1/1616588346705_117.png",
                                "image_url": "https://resolve-dev-backend.s3.us-east-"
                                "type": "Sheet",
                                "item_id": 1,
                                "file_id": 1,
                                "user_id": 2,
                                "created_at": "2021-03-24 17:19:09",
                                "updated_at": "2021-03-24 17:19:09",
                                "created_by": 2,
                                "updated_by": null,
                                "deleted_at": null,
                                "markup": [
                                    {
                                        "id": 1,
                                        "item_id": 1,
                                        "sheet_id": 1,
                                        "assignee_id": null,
                                        "editor_details": "{\"a\": \"b\", \"c\": \"d\"}",
                                        "visibility": "private",
                                        "image_url": "{\"a\": \"b\", \"c\": \"d\"}",
                                        "priority": "low",
                                        "resolved_by": 2,
                                        "resolved_on": "2021-03-",
                                        "due_date": null,
                                        "created_by": 2,
                                        "created_at": "2021-03-24 18:30:21",
                                        "updated_at": "2021-03-24 19:12:39",
                                        "deleted_at": null,
                                        "comment": []
                                    }
                                ]
                            }
                        ]
                    }
                ],

但我不需要 project_id 等,例如每个表中的某些字段,
例如我只需要文件表中的这些字段,并希望从我的查询中的每个表中获取特定字段,但我在邮递员中得到高于输出响应

                     ```
                    "id": 1,
                    "actual_name": "10 -Rehan Shakeel - Feb2021.pdf",
                    "image_url": "https://resolve-dev/file/2/1/1/1616588346705_117.pdf",
                    "media_type": "profile",
                    "created_at": "2021-03-24 17:19:05",
                    "updated_at": "2021-03-24 17:19:05",
                    "deleted_at": null,
                        ```
                    
4

1 回答 1

0

尝试使用数组内的列添加 select 语句

const project = await Project.query()
      .select(['tableyouwant.id', 'actual_name', 'image_url', 'media_type', ..........])
      .where('id', project_id)
      .with('items.file.sheets.markup.comment.attachment').first()
于 2021-04-13T02:38:28.723 回答