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.

Service / SDL generation is broken when using relations

See original GitHub issue

I’m noticing when you have a relation column that has a different name then the Table it is referring to you get an error like this:

  ✖ Generating SDL files...
    → No schema definition found for `Author` in schema.prisma file
No schema definition found for `Author` in schema.prisma file

This happens when you for example have two tables, Post and User, and you name the user relation different on Post like this:

model Post {
  id       Int    @id @default(autoincrement())
  title    String
  author   User   @relation(fields: [authorId], references: [id])
  authorId Int
}

model User {
  id    Int    @id @default(autoincrement())
  posts Post[]
}

To make it easier to reproduce you can use this repo/branch: https://github.com/jvanbaarsen/rw-examples

It happens when you run: yarn rw g sdl post

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
cannikincommented, Feb 24, 2021

HMMMM

The error is coming from here: https://github.com/redwoodjs/redwood/blob/main/packages/cli/src/lib/index.js#L35-L64 But the code that calls that is this line I’m guessing: https://github.com/redwoodjs/redwood/blob/main/packages/cli/src/commands/generate/sdl/sdl.js#L112 Which specifically tries to look it up by field.type, which would be User or ThingOne, which is correct. hmmmmmmmmm

1reaction
brentjandersoncommented, Feb 23, 2021

I’ve run into the same issue. Oddly, I can get it to work in some circumstances but not in othes:

This does not work

model ThingOne {
  id   String @id @default(uuid())
  name String // Why is this needed?

  oneReferencesOnThingTwo      ThingTwo[] @relation("OneReferenceOnThingTwo")
  anotherReferencessOnThingTwo ThingTwo[] @relation("AnotherReferenceOnThingTwo")
}

model ThingTwo {
  id String @id @default(uuid())

  oneReferenceToThingOne       ThingOne  @relation("OneReferenceOnThingTwo", fields: [oneReferenceToThingOneId], references: [id])
  oneReferenceToThingOneId     String
  anotherReferenceToThingOne   ThingOne? @relation("AnotherReferenceOnThingTwo", fields: [anotherReferenceToThingOneId], references: [id])
  anotherReferenceToThingOneId String?
}

This does work

model ThingOne {
  id   String @id @default(uuid())
  name String // Why is this needed?

  oneReferencesOnThingTwo      ThingTwo[] @relation("OneReferenceOnThingTwo")
  anotherReferencessOnThingTwo ThingTwo[] @relation("AnotherReferenceOnThingTwo")
}

model ThingTwo {
  id String @id @default(uuid())

  thingOne          ThingOne  @relation("OneReferenceOnThingTwo", fields: [thingOneId], references: [id])
  thingOneId        String
  anotherThingOne   ThingOne? @relation("AnotherReferenceOnThingTwo", fields: [anotherThingOneId], references: [id])
  anotherThingOneId String?
}

The diff, if it helps:

model ThingOne {
  id   String @id @default(uuid())
  name String // Why is this needed?

  oneReferencesOnThingTwo      ThingTwo[] @relation("OneReferenceOnThingTwo")
  anotherReferencessOnThingTwo ThingTwo[] @relation("AnotherReferenceOnThingTwo")
}

model ThingTwo {
  id String @id @default(uuid())

-  oneReferenceToThingOne       ThingOne  @relation("OneReferenceOnThingTwo", fields: [oneReferenceToThingOneId], references: [id])
+  thingOne                     ThingOne  @relation("OneReferenceOnThingTwo", fields: [thingOneId], references: [id])
-  oneReferenceToThingOneId     String
+  thingOneId        String
-  anotherReferenceToThingOne   ThingOne? @relation("AnotherReferenceOnThingTwo", fields: [anotherReferenceToThingOneId], references: [id])
+  anotherThingOne   ThingOne? @relation("AnotherReferenceOnThingTwo", fields: [anotherThingOneId], references: [id])
-  anotherReferenceToThingOneId String?
+  anotherThingOneId String?
}

I’ve put up a repo demoing this issue. I’ve tagged the commit where it does not work as broken and the commit where it does work as works. The way to test it:

git checkout broken && yarn rw g sdl -f ThingTwo should give you an error:

No schema definition found for `OneReferenceToThingOne` in schema.prisma file

I don’t know what significance there is in the difference between each model. But it’s weird that one works, the other doesn’t, and unless I’m staring past it the only thing that has changed is the name of the fields?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Separate generated services and SDL files from custom ones
Maybe it's when I generate service on it's own separately from SDL (not sure) or there are “errors” in SDL(?). I just now...
Read more >
Full article: Towards a service-led relationship in project-based firms
The findings show that the uniqueness and dynamics of projects necessitate the adoption of both SDL and RM, a view that is entitled...
Read more >
Modeling Web Services with UML
What is a Web Service? • Represents a specific business function. • Exposed by a company. • Usually through an Internet connection.
Read more >
SdL - River Thames Conditions - Environment Agency - GOV.UK
Cars garages in cornwall, Broyhill chairside table with usb? ... Nerd world media, 60k service cost, Salmo do dia 22 de outubro 2013,...
Read more >
(PDF) Service-dominant logic and the business model concept
Companies are recently affected by an ongoing change of customer behaviour. Customers are no longer solely interested in product offerings ...
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