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

How to specify implicit many-to-many relations? #7

Closed
NexZhu opened this issue Jun 9, 2022 · 5 comments
Closed

How to specify implicit many-to-many relations? #7

NexZhu opened this issue Jun 9, 2022 · 5 comments

Comments

@NexZhu
Copy link

NexZhu commented Jun 9, 2022

How to produce Prisma schema like:
https://www.prisma.io/docs/concepts/components/prisma-schema/relations/many-to-many-relations#implicit-many-to-many-relations

model Post {
  id         Int        @id @default(autoincrement())
  categories Category[]
}

model Category {
  id    Int    @id @default(autoincrement())
  posts Post[]
}
@NexZhu NexZhu closed this as completed Jun 9, 2022
@cwqt
Copy link
Owner

cwqt commented Jun 10, 2022

I'll work on adding a ManyToMany field type, in the mean-time you can use Raw()

Post
  .Field("id", Int(Id, Default("autoincrement()")))
  .Raw("categories Category[]")

@cwqt
Copy link
Owner

cwqt commented Jun 11, 2022

Actually you can do:

const Post = Model('Post');
const Category = Model('Category');

Post
  .Field('id',            Int(Id, Default('autoincrement()')))
  .Relation('categories', OneToMany(Category));

Category
  .Field('id',            Int(Id, Default('autoincrement()')))
  .Relation('posts',      OneToMany(Post));

image

@NexZhu
Copy link
Author

NexZhu commented Jun 13, 2022

Actually you can do:

const Post = Model('Post');
const Category = Model('Category');

Post
  .Field('id',            Int(Id, Default('autoincrement()')))
  .Relation('categories', OneToMany(Category));

Category
  .Field('id',            Int(Id, Default('autoincrement()')))
  .Relation('posts',      OneToMany(Post));
image

Yeah, I closed because I found this solution, thanks :D

@NexZhu
Copy link
Author

NexZhu commented Jun 13, 2022

Better add it to the doc/example though

@cwqt
Copy link
Owner

cwqt commented Jun 13, 2022

eb43ae8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants