V8-archive: User behaviour like relational field

Created on 16 Dec 2018  路  16Comments  路  Source: directus/v8-archive

I created a members collection referencing users in directus_users table (using User content type). When I request the items of members with the API it's not possible to resolve the users relation. I'm only getting the users id.
As a workaround I'm now using a M2O relation to resolve the user details, but actually I expected the User type to behave like a relation.

duplicate

Most helpful comment

Beat me to it by 18 seconds @benhaynes 馃槃

All 16 comments

Does the user trying to read the table have permissions to read the Directus_user table? And are you also appending ?fields=*.* to get related information?

I was using the admin user and I also appended ?fields=*.* in order to resolve the relation.

And just to confirm when you say you used the user content type, you mean you used the interface of User?

Yes, exactly.

Hey @maettyhawk, can you share the schema you are using so we can take a look why there's not a relationship in your user field?

Hey @WellingGuzman, here's how to reproduce:

  • add new collection (f.e. "member")
  • add field "user" using the User interface (=> collection has only two fields: id and user)
  • create new item -> select existing user
  • access /items/member?fields=*.*(I also tried /items/member?fields=* and /items/member?fields=*.*.*)
  • response (user is not getting resolved):
    { "data": [ { "id": 1, "user": 1 } ] }

The schema of the user field is the interfaces default, I didn't change any settings.

I believe this is a duplicate of https://github.com/directus/api/issues/495

You鈥榬e right, @rijkvanzanten.

Thanks for clarifying @maettyhawk. I will close this in favor of #495.

Hey @maettyhawk can you give the schema you are using that is having this issue. I confirmed this was already implemented.

@WellingGuzman I think I鈥榤 not sure what you mean with the scheme. 馃槙

Either a full database dump (ideal if possible). Or the table/column architecture and the values within directus_relations. @maettyhawk

@maettyhawk The way you setup the database, eg what fields in use etc. You can share a full SQL dump (if you don't have any private info in it) if you want. That allows @WellingGuzman to reproduce your full setup 1 to 1 to be able to see what's up

Beat me to it by 18 seconds @benhaynes 馃槃

Here you are! Btw: I cleared the user passwords.
dump.zip

Hey @WellingGuzman, here's how to reproduce:

* add new collection (f.e. "member")

* add field "user" using the User interface (=> collection has only two fields: id and user)

* create new item -> select existing user

* access `/items/member?fields=*.* `(I also tried `/items/member?fields=*` and `/items/member?fields=*.*.*`)

* response (user is not getting resolved):
  `{ "data": [ { "id": 1, "user": 1 } ] }`

The schema of the user field is the interfaces default, I didn't change any settings.

This is an expected behavior, I don't know what was the process in the app, but there's only one two user types and those are user_created and user_updated. You create an integer field with an user interface.

You need to create a relationship for the user field to directus_users.

I will close this ticket as this is not a bug with the API. The fields was not configured properly.


For some odd reason I don't know why I could it fix it without deleting and creating the table again. That's another thing for another day.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

magikstm picture magikstm  路  3Comments

metalmarco picture metalmarco  路  3Comments

Nitwel picture Nitwel  路  3Comments

benhaynes picture benhaynes  路  4Comments

maettyhawk picture maettyhawk  路  3Comments