Skip to content
This repository has been archived by the owner on Jan 6, 2023. It is now read-only.

Query parmeter: fields not working with field "Created By" #546

Closed
Marcnuth opened this issue Oct 31, 2018 · 8 comments
Closed

Query parmeter: fields not working with field "Created By" #546

Marcnuth opened this issue Oct 31, 2018 · 8 comments

Comments

@Marcnuth
Copy link

Marcnuth commented Oct 31, 2018

I created a collection named "pages", and the collection only have 4 field:

  • ID: the default field
  • content: a text field with field type = string
  • created_by: a User field with field type = User Created
  • created_on: a DataTime field with field type = DateTime Created

When I try to use the API:

GET /items/pages?fields=*.*

The response is like:

{
data: [
  {id:1, content: 'blabla', created_on: 'a time string', created_by: 1},
  {id:2, content: 'bla222', created_on: 'time string', created_by: 1 }
]
}

In the response, the created_by only returns the ID of the user instead of the details of the user.
However, according to the docs, when I specify fields=*.*, the created_by field should be filled with details.

Note: My API version is the latest releases 2.0.4.
Please check this.

Thanks in advance.

@Marcnuth
Copy link
Author

I did some debugging, and found the reason is:

No record is created in directus_relations table, so the API cannot find the detail of user.

However, why no record is created in directus_relations table?
Please fix this.

@rijkvanzanten
Copy link
Member

@wellingguzman user_created / user_updated should automatically relate to directus_users right? Just like the file type relates to directus_files?

@benhaynes
Copy link
Sponsor Member

benhaynes commented Oct 31, 2018

When we say "automatically" do we mean that it will automatically create the relationship (in directus_relations) when the field is created, or that the API will automatically return the relational data without the relationship defined in the database?

@wellingguzman
Copy link
Contributor

The API should automatically set this relationship in "runtime" (not creating the relationship in the directus_relations table).

@wellingguzman wellingguzman added this to Critical in Bug Triage Oct 31, 2018
@wellingguzman wellingguzman added this to To do in v2.0.5 Oct 31, 2018
@wellingguzman wellingguzman moved this from To do to In progress in v2.0.5 Oct 31, 2018
@KPChakravarthy
Copy link

Here's my collection -

ID: the default field
title: a text field with field type = string
story: a WYSIWYG editor
banner_image: a featured image
categories: a list of categories to select from
created_by: a User field with field type = User Created
created_on: a DataTime field with field type = DateTime Created

API call =
GET /items/stories?fields=*.*

Response =

    "data": [
        {
            "id": 8,
            "title": "Test",
            "banner_image": {
                "id": 1,
                "storage": "local",
                "filename": "love.jpg",
                "title": "Love",
                "type": "image/jpeg",
                "uploaded_by": 1,
                "uploaded_on": "2018-10-30T19:21:38+00:00",
                "charset": "binary",
                "filesize": 52498,
                "width": 800,
                "height": 450,
                "duration": null,
                "embed": null,
                "folder": null,
                "description": "",
                "location": "",
                "tags": [],
                "metadata": null,
                "data": {
                    "full_url": "http://thewriteaddict.com/directus/public/uploads/_/originals/love.jpg",
                    "url": "/uploads/_/originals/love.jpg",
                    "thumbnails": [
                        {
                            "url": "http://thewriteaddict.com/directus/public/thumbnail/_/200/200/crop/good/love.jpg",
                            "relative_url": "/thumbnail/_/200/200/crop/good/love.jpg",
                            "dimension": "200x200",
                            "width": 200,
                            "height": 200
                        }
                    ],
                    "embed": null
                }
            },
            "story": "<p>Test story</p>",
            "created_on": null,
            "author": {
                "id": 1
            },
            "categories": [
                {
                    "id": 14,
                    "story_id": "8",
                    "category_id": "1"
                }
            ]
        }
    ],
    "public": true
}```

As you can see, the `created_on` returns `null` and `author` returns only `id`

Bug Triage automation moved this from Critical to Closed Oct 31, 2018
v2.0.5 automation moved this from In progress to Done Oct 31, 2018
@wellingguzman
Copy link
Contributor

I pushed this patch cf67174, to automatically set the default relationship for users type.

@Marcnuth + @KPChakravarthy this patch will fix this problem.

@Marcnuth
Copy link
Author

Marcnuth commented Nov 4, 2018

@wellingguzman @benhaynes

The patch does fix the problem.
However, if I delete a relation field in a collection, the record in directus_relation won't be deleted.
Please fix this at the same time.

@benhaynes
Copy link
Sponsor Member

Hey @Marcnuth – this is a known issue being tracked in a different ticket:

https://github.com/directus/app/issues/1045

I'll leave this one closed and you can follow the progress in the other one.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Bug Triage
  
Closed
v2.0.5
  
Done
Development

No branches or pull requests

5 participants