I can't find any seriously clean notes about this,...
# gooddata-cloud
r
I can't find any seriously clean notes about this, but in our LDM our pkeys are being repeated across tables. So I have 6 tables that are all connected off of our
case_interaction_id
field, and it's showing up 6 times in the model. Is there something I've just completely missed to set this up so there's exactly one?
j
Hi Ryan, As per our documentation: https://www.gooddata.com/docs/cloud/model-data/concepts/primary-key/
You can have only one primary key per dataset, but you can have multiple other datasets in the LDM with references to that primary key. Any single reference in a dataset can point back to only one primary key.
So if you need to reference a single pk from multiple datasets, you can use the foreign keys in them to reference it. I’m not aware with your data model but that can be a standard procedure. If you’re looking for some basics regarding data modeling, I would strongly recommend you to check our university courses which are covering this topic as well: https://university.gooddata.com/courses/designing-data-models/
r
So what you've said is what we do, but it's showing as having each of those fields when we go to select them anywhere in GD. Below is a snippet of our model; our central table for a star shaped schema, with
case_interaction_id
being our PK for all sets. Because it needs to exist within both tables to functionally join, it's showing up as 2 different fields to select. I'm just curious how we prevent that.
j
Thanks for the screenshot. I’m not sure how you exactly got to that state of LDM but you could definitely try to go to edit mode and use the ‘set primary key’ option:
and un-select it so it remains as a foreign key:
r
so - that's how it's set. Both tables show it as a pkey though, and I can't join without a pkey. Paired with those facts, now it shows up multiple times.
j
even if you un-select it as a primary key? could you please un-select it and show screenshot showing that it’s still showing as pkey?
r
if I unselect it, it says "You are required to have a primary key to maintain a join". Should I delete the join as well?
j
or alternatively, you can create some other primary key in that problematic tables and then it should let you to use
case_interaction_id
as a foreign key, would that work for you?
r
I'm still not sure how to set it as a foreign key in the system. I think that's the piece I'm curious about.
j
Hi Ryan, You can find information on setting the reference to the primary key (or, foreign key) HERE. Let us know if this helps in your LDM construction, or if you have any further questions.