Prisma1: Allowing additonal scalars to @relationTable

Created on 3 Apr 2019  路  4Comments  路  Source: prisma/prisma1

Is your feature request related to a problem? Please describe.
I'd like to allow manual ordering of relations by adding an index field to a mapping table (@relationTable). In our app, the user could move around related nodes via a drag and drop UI, this will update the index. On the API side, I can then pass either the index or make the index the default param for ordering.

Describe the solution you'd like
With the new data model 1.1, the @relationTable directive gets introduced. Unfortunately, adding the index field here yields: A link table must not specify any additional scalar fields. (seems to be outdated wording here also "link table")

My perfect solution for this would be to allow extension of the mapping table and then expose API methods to manipulate the values.

Describe alternatives you've considered
I am aware that this can be done via an additinal custom type, but this won't allow a clean API at the end.

kinfeature aredatamodel rf0-needs-spec

Most helpful comment

Hey, it seems like this could solve our needs. One issue I discovered is that if we use the approach for allowing to save a prio to allow ordering of relations like in the example:

```type User {
id: ID! @id
name: String!
posts: [UserPost!]!
}

type UserPost {
id: ID! @id
user: User! @relation(link: INLINE)
post: Post! @relation(link: INLINE)
prio: Int!
}

type Post {
id: ID! @id
headline: String!
user: UserPost!
}

We would lose the ability to order by any of the properties of the two relation sides:

{
users {
id
name
posts(orderBy:prio_ASC) {
post {
headline
}
}
}
}

Relational orderby would solve this though:

{
users {
id
name
posts(orderBy:{prio: ASC, post: { headline: ASC}}) {
post {
headline
}
}
}
}
```

All 4 comments

Would this solve your issue?

type User {
  id: ID! @id 
  posts: [JoinTable!]!
}

type JoinTable {
  id: ID! @id 
  user: User! @relation(link: INLINE)
  post: Post! @relation(link: INLINE)
}

type Post {
  id: ID! @id 
  user: JoinTable!
}

This might be a solution, we will test it out! It is available in 1.30 already, right?

It seems it is not supported for n:m but I don't know right now if this is an issue as I believe that you could emulate n:m with this. Need to wrap my head around and will get back, thanks!

Hey, it seems like this could solve our needs. One issue I discovered is that if we use the approach for allowing to save a prio to allow ordering of relations like in the example:

```type User {
id: ID! @id
name: String!
posts: [UserPost!]!
}

type UserPost {
id: ID! @id
user: User! @relation(link: INLINE)
post: Post! @relation(link: INLINE)
prio: Int!
}

type Post {
id: ID! @id
headline: String!
user: UserPost!
}

We would lose the ability to order by any of the properties of the two relation sides:

{
users {
id
name
posts(orderBy:prio_ASC) {
post {
headline
}
}
}
}

Relational orderby would solve this though:

{
users {
id
name
posts(orderBy:{prio: ASC, post: { headline: ASC}}) {
post {
headline
}
}
}
}
```

Is there an example showing the current recommended way to achieve this? I'm interested to see both the schema and how one would run a query with ordering or update the order.

Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ragnorc picture ragnorc  路  3Comments

MitkoTschimev picture MitkoTschimev  路  3Comments

AlessandroAnnini picture AlessandroAnnini  路  3Comments

nikolasburk picture nikolasburk  路  3Comments

akoenig picture akoenig  路  3Comments