Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot get related value in field display when more than 2 tables are related with each other. #22380

Open
w4-asad opened this issue May 3, 2024 · 1 comment
Labels

Comments

@w4-asad
Copy link

w4-asad commented May 3, 2024

Describe the Bug

Hi There, I just found out that when more than 2 tables are related and I try to display the related value then it shows empty value on UI, but after I save the record, the relation works perfectly, so I know the relation is not wrong there. Anyways I'm adding minimal tables schema so you know what I mean.

Schema:

CREATE TABLE public.users (
	"uuid" uuid NOT NULL,
	name varchar(100) NULL
);
CREATE TABLE public.permissions (
	permission_key varchar(50) NOT NULL,
	permission_label varchar(50) NULL,
	CONSTRAINT permissions_pkey PRIMARY KEY (permission_key)
);
CREATE TABLE public.user_permissions (
	"uuid" uuid NOT NULL,
	user_uuid uuid NULL,
	permission_key varchar(100) NULL,
	CONSTRAINT user_permissions_pkey PRIMARY KEY (uuid)
);
ALTER TABLE public.user_permissions ADD CONSTRAINT user_permissions_user_uuid_fkey FOREIGN KEY (user_uuid) REFERENCES public.users("uuid") ON DELETE SET NULL;
ALTER TABLE public.user_permissions ADD CONSTRAINT user_permissions_permission_key_fkey FOREIGN KEY (permission_key) REFERENCES public.permissions(permission_key);

Basically in "users" collection, I've added a one to many field (permissions) which have a relation to user_permissions with users.uuid = user_permissions.user_uuid and "user_permissions.permission_key" is related to "permissions" table with user_permissions.permission_key = permissions.permission_key.

And in user_permissions.permission_key field's display settings, I've chose "Related Values" and displayed the value of permissions.permission_label and then in users collection, field users.permissions (one to many field) have display set to "Related Values" and I've selected related field user_permissions.permission_key. So it's a relation of 3 tables in this case. I'll attach screenshots to visually show the issue as well.

In following screenshot, I opened a user record and it shows permissions correctly, so that means the relation is working and it's showing value of permissions.permission_label
image

But when I add a new permission, the value appears empty.
image

And when I save the record, it'll save the permissions correctly and then when editing the same record again, it'll show the value correctly as shown in following screenshot.
image

I'm using Directus v10.10.4 with postgres v16.1

To Reproduce

  • Create the 3 tables in postgres database
  • Configure the fields as I've mentioned above
  • Try to select a permission and label will not appear there until you save the record

Directus Version

v10.10.4

Hosting Strategy

Self-Hosted (Docker Image)

@liminghua999
Copy link

liminghua999 commented May 8, 2024

It appears I have the same question:
I am using Gorm to create a table. When I define a many-to-many relationship and create the table,
the Directus UI does not display the field defined as many-to-many.

type Device struct {
	gorm.Model
	Hostname string `gorm:"unique"`
        Svcs []*Svc `gorm:"many2many:device_svc;"`
}
type Svc struct {
	gorm.Model
	Name string
        Devices     []*Device `gorm:"many2many:device_svc;"`
}

the directus ui just show hostname field,not show svcs field

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: 📋 Backlog
Development

No branches or pull requests

3 participants