question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Introspection composite foreign keys pointing to composite primary keys

See original GitHub issue
create table a (
  one integer not null,
  two integer not null,
  primary key ("one", "two")
);
create table b (
  one integer not null,
  two integer not null,
  foreign key ("one", "two") references a ("one", "two")
);
insert into a ("one", "two") values (1, 2);
insert into b ("one", "two") values (1, 2);
model a {
  one Int
  two Int
  bs  b[] @relation(references: [a])

  @@id([one, two])
}

model b {
  a a @map(["one", "two"])
}

The @relation(references: [a]) seems wrong, at least I can’t understand this.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
do4grcommented, Feb 17, 2020

Yep, as long as you do not add an ID on b that is the expected result.

0reactions
janpiocommented, Feb 18, 2020

Can you please update the integration test to include an explicit ID here @matthewmueller?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mapping a composite foreign key to a composite primary key
I'm having problems mapping composite keys in jpa / hibernate. The parent entity and the child entity both have composite primary keys.
Read more >
Composite and Foreign Keys as Primary Key - ORM - Doctrine
Doctrine ORM supports composite primary keys natively. Composite keys are a very powerful relational database concept and we took good care to make...
Read more >
Defining Composite Primary and Foreign Keys - IBM
A composite key specifies multiple columns for a primary-key or foreign-key constraint. The next example creates two tables. The first table has a...
Read more >
What are explanations of primary key, foreign key, composite ...
A Composite Primary Key (CPK) is a key that uses 2 or more columns to uniquely identify each row in a table. They...
Read more >
Composite and Foreign Keys as Primary Key - MikroORM
Composite and Foreign Keys as Primary Key · General Considerations​ · Primitive Types only​ · Identity through foreign Entities​ · Use-Case 1: Dynamic...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found