Foreign keys as primary values [Apr 19]

:raising_hand_man: Harbard asked

Hi, it’s me again !

So I’m using my DB to handle translation, and I’d like to set foreign keys as primary values to avoid getting IDs in my tables.

I see in the code https://github.com/nocodb/nocodb/blob/master/packages/nc-gui/components/project/spreadsheet/components/virtualHeaderCell.vue#L69 that the setAsPrimaryValue is not available for foreign keys, is there a technical reason. Is it worth that I spend some time trying to implement this in a PR ?

```sql

drop table if exists labels cascade;

CREATE TABLE labels (

id serial primary key,

en text,

fr text,

de text

);

drop table if exists schools cascade;

CREATE TABLE schools (

id serial primary key,

school_label int references labels(id)

);

drop table if exists class_rooms cascade;

CREATE TABLE class_rooms (

id serial primary key,

class_label int references labels(id),

school_id int references schools(id)

);

drop table if exists students cascade;

CREATE TABLE students (

id serial primary key,

std_label int references labels(id),

class_id int references class_rooms(id)

);

INSERT INTO public.labels (en,fr,de) VALUES

(‘school_1’,‘ecole_1’,NULL),

(‘school_2’,‘ecole_2’,NULL),

(‘class_1’,‘classe_1’,NULL),

(‘class_2’,‘classe_2’,NULL),

(‘class_3’,‘classe_3’,NULL),

(‘std_1’,‘eleve_1’,NULL),

(‘std_2’,‘eleve_2’,NULL),

(‘std_3’,‘eleve_3’,NULL),

(‘std_4’,‘eleve_4’,NULL),

(‘std_5’,‘eleve_5’,NULL);

INSERT INTO public.schools (school_label) VALUES

(1),

(2);

INSERT INTO public.class_rooms (class_label,school_id) VALUES

(3,1),

(4,1),

(5,2);

INSERT INTO public.students (std_label,class_id) VALUES

(6,1),

(7,1),

(8,2),

(9,3),

(10,3);

```

image0

:person_tipping_hand: o1lab replied

The idea of foreign key is mostly for machines :slightly_smiling_face: and hence we are avoiding that to be set as primary values

:person_tipping_hand: o1lab replied

the idea of primary value is that it has to be humanly understandabale

:raising_hand_man: Harbard replied

I understand your point. The thing is, I really need a relational DB for my use case, and I also need non-dev people to work on the DB. So nocoDB seems to be the perfect tool here !

Is my DB structure exotic ? Because I feel like it’s pretty commun. Let’s say I want to creat a new classroom and attach it to a school, the user will be faced with PK instead of the label.

:raising_hand_man: Harbard replied

Anyway, I’d be glad to discuss this topic with anyone in the team and try to help ! :pray:

:raising_hand_man: Harbard replied

What is the best place to talk about this ? Here, an issue or GitHub discussions ?

:raising_hand_man: Harbard replied

<a:kbInklingWave:630956774727483422> What do you guys think about that ?

Autogenerated from discord


Join NocoDB’s community

DiscordTwitterRedditDocs