I can use `orderBy` on the `dishes` but that seems...
# prisma-whats-new
b
I can use
orderBy
on the
dishes
but that seems to relate to the
Dish
entities (id, created, updated)
d
The solution is to have an intermediate type to represent the particular Dish on the Meal. So you'd have a type called something like MealDish which would have relationships with both Meal and Dish and would include the orderIndex field
you may also find this type useful for other things in the future. I don't know your use case but I often find that these kind of relationships end up attracting other metadata and relationships
For example, if you enable someone to add a comment to a particular dish in a meal, it would make sense for the MealDish type to connec tto the comment, so you know which meal and which dish the comment was about
b
Can you explain a bit more how that would work? Maybe writing pseudo queries? I already do something similar actually at another level, really when I said
Dish
it was a
Favourite
which has a link to
Dish
and
User
so I guess similar idea?
d
The MealDish type would have a 1-n relationship with Meal and a 1-n relationship with Dish, plus the orderIndex field
b
I would have to maintain
orderIndex
myself? or is that something offered by graph.cool?
d
No - you have to manage it yourself
I just do it client side but if you want to have it managed server side, you could use a Request Pipeline function or a Schema Extension to take care of it
Your other option if the order will never change is to just use the createdAt values on a MealDish type
b
I see, and then when I query, I’d do something like:
Copy code
{
  allMeals {
    id
    date
    type
    mealDishes(orderBy: orderIndex_DESC) {
      id
      dish {
        id
        name
      }
    }
  }
}
d
(assuming they are not created simultaneously)
yes, exactly
b
great
thanks that makes sense
the second option makes sense too
h
Or add an ordering (default 0) and a created by and order by both, that way default it will order on created date but you can overwrite it when needed 🙂
d
I'd do an ASC sort rather than DESC but that depends on how you are going to display the data I guess
That's a good idea @hvdklauw
b
for my use case, the order doesn’t actually change
I literrally want it to always be the order in which the user adds them
h
ah, was just seeing if you actually could order on multiple values or not.. not sure how to do that, but I guess that's not an issue then
b
see the use case above
you’ll see why I want the “added at” order to be retained
h
Yeah
b
but cheers both of you, seems like adding another intermediary entity is the way to go
h
As reference: Multi field ordering does not work yet: https://github.com/graphcool/feature-requests/issues/62
b
only negative is it becomes quite difficult naming things once you have to add a few levels of intermediary entities!
worse part being the relation names and generated mutations
h
b
haha
yep!
cheers! 👍