<@U0RQY0KK5> Here it says you can use the float ty...
# prisma-whats-new
w
@nilan Here it says you can use the float type - what does that mean? https://www.graph.cool/forum/t/insert-object-in-a-relation-at-given-index/860/2
n
so, instead of using integer positions 0, 1, 2, you could use float positions 1, 1.5, 2, 2.5, 3, so reordering items is easier
w
Ohh - so there is no way to maintain order with a list of related items?
I was hoping it was like an array where the last item was the last added
n
that's not how it works - the nodes need to encode their position
alternatively, you store a list of strings, which are the ids of the separate items
w
makes sense - so I’d need to make another Type for my cart rather than just holding it it directly
with Strings, can I still populate with graphql?
n
I think in your case it's fine to put
position
on
Item
w
would position not be shared by everyone with that item in their cart though? or is it not updated?
n
that's true! I thought you are creating new items for every cart 🙂
w
hmm okay -so only way is to make another type then
n
is there a reason you are not using separate items per cart?
w
Maybe I’m missing something - I have Items and I just add them to the users cart. You are suggesting copying the item when someone adds it to their cart?
n
Hey @wesbos - Here is what I have for my Cart schema…
Copy code
type Cart {
  id: ID! @isUnique
  items: [CartItem!]! @relation(name: "CartItems")
  createdAt: DateTime!
  updatedAt: DateTime!
}

type CartItem {
  id: ID! @isUnique
  orderedItem: Variant! @relation(name: "OrderedCartItem")
  quantity: Int @defaultValue(value: 1)
  cart: Cart @relation(name: "CartItems")
  createdAt: DateTime!
  updatedAt: DateTime!
}
OrderedItem
is a relation to the
Product
(or Variant in my case)
n
yea and if you would add a field
position
to the
CartItem
type of @notrab, you could sort the items specific to one cart
w
@notrab so you have three types then, right? Cart, CartItem and Item?
n
ah, maybe this is what you meant before. yes, the idea is to have item "templates" that contain the meta data like name, description and price
w
Yeah makes sense - I think I’ll go that route
n
while the item in a cart only contains the quantity and the position
w
and then to associate that with a user, it’s a 4th type
was hoping I could only do it with 2 types - oh well
n
That’s right @wesbos - I struggled trying to come up with a similar thing. There is even a problem with this approach if you stop at this level, but what I’ve decided to do is when an order is created, copy the values to Order and OrderItem’s. as a orderedItem could change or be deleted, that would mess things up in the future.
w
yeah good point - that makes sense
thanks for the help 🙂
👍 1
n
@notrab is a webshop champ 😄 💯
😂 1