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

Introspection composite foreign keys pointing to composite primary keys #1599

Closed
matthewmueller opened this issue Feb 13, 2020 · 5 comments · Fixed by prisma/prisma-engines#497 or #1768
Assignees
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug.

Comments

@matthewmueller
Copy link
Contributor

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.

@janpio
Copy link
Member

janpio commented Feb 14, 2020

Can you run this test again @matthewmueller? The Introspection result should probably be different now.

@janpio janpio reopened this Feb 14, 2020
@janpio janpio added this to the Preview 22 milestone Feb 14, 2020
@matthewmueller
Copy link
Contributor Author

matthewmueller commented Feb 17, 2020

Is this now the expected result from introspection?

generator client {
  provider = "prisma-client-js"
  output   = "${tmp}"
}

datasource pg {
  provider = "postgresql"
  url      = "${connectionString}"
}

model a {
  one Int
  two Int

  @@id([one, two])
}

/// The underlying table does not contain a unique identifier and can therefore currently not be handled.
// model b {
  // a a @map(["one", "two"])
// }

It gives an unexpected token when parsing, but hopefully that's fixed by the recent merge.

@janpio
Copy link
Member

janpio commented Feb 17, 2020

You'll probably get more insight by adding an explicit ID or Unique to the b table. Right now that table is a bit too minimal for PRisma ;)

@do4gr
Copy link
Member

do4gr commented Feb 17, 2020

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

@janpio janpio assigned matthewmueller and unassigned do4gr Feb 18, 2020
@janpio
Copy link
Member

janpio commented Feb 18, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug.
Projects
None yet
4 participants