Can't declare foreign key relationship in module schemas/<schema>.xml metadata

LabKey Support Forum
Can't declare foreign key relationship in module schemas/<schema>.xml metadata Will Holtz  2018-07-30 18:47
Status: Closed
 

Hi,

I made a hard table that contains a foreign key to a Labkey userid (beyond the standard userid fields of createdby, modifiedby, owner). In the module schemas/<schema>.xml metadata I declared the foreign key. In my grid views, I could not get the userid lookup to occur; the integer value was displayed, not the displayname field. I know there are a lot of restrictions on access to core.users and related tables and I thought I was just not getting some of that right. However, I eventually realized that by declaring the foreign key in the module queries/<schema>/<query>.query.xml metadata, I was able to get the lookup to work. It is unclear to me if there is some reason why the foreign key declaration in the schema/<schema>.xml file did not work or if this behavior is unexpected.

I made a minimal reproduction that is contained in the attached module file. In this module, two identical hard tables are created. UserMetadata.SchemaMetadata has the foreign key declared in schemas/UserMetadata.xml. UserMetadata.QueryMetadata has the foreign key declared in queries/UserMetadata/QueryMetadata.query.xml. In both tables, "associateduser" is the userid field I am trying to get the foreign key metadata applied to such that the lookup of displayname occurs. In the Labkey query browser, the associateduser field in UserMetadata.SchemaMetadata does not show a lookup column, while the same field in the UserMetadata.QueryMetadata table has "core.Users.UserId (DisplayName)" as the Lookup column.

I did my testing on Labkey v18.2, Postgres v10.4, Tomcat v8.5.24.

thanks,
-Will

 
 
Will Holtz responded:  2018-08-06 17:02

It appears I asked this same question in a slightly different way 2 years ago..
https://www.labkey.org/9e077eeb-b2ab-1029-961c-79704b7a2169/announcements-thread.view?entityId=0e688e74-c7ba-1033-bc76-a3afb1590fd0&_docid=thread%3A0e688e74-c7ba-1033-bc76-a3afb1590fd0

And looking back at Josh's old answer has cleared this up for me yet again.

-Will