2

Edit: I revised and deleted to clarify. The analogy goes... Every time I get a new customer, I want to automatically create 100 orders for them because I know all my customers want the same 100 items. But they need to be able to change the quantity after they sign up since they want different quantities. Right now I create 100 orders on the client side by .map()ing through the array of 100 orders and doing createOrder mutations in graphql (apollo), is there a better way to do this?

EDIT 2: I believe doing it on the server side at the database makes more sense. Any other advice appreciated.

Kevin Danikowski
  • 4,620
  • 6
  • 41
  • 75
  • I've gotten a +1 on both this question and the similar one I made. Does no body have any idea how to do this? Or possibly a research that I should do I google to help find the answer? – Kevin Danikowski Nov 10 '17 at 01:11
  • 1
    Do you have a users table? What DBMS are you using? – SE1986 Nov 11 '17 at 00:00
  • @SEarle1986 I am using graph cool. I do have a users table. In graph cool I was going to attempt to create a function to do what I'm currently doing on the client side – Kevin Danikowski Nov 11 '17 at 00:05
  • 1
    It seems graph cool is built on Amazon Aurora which in turn is built on Postgres / MySQL. If database triggers are supported on this platform, I'd look at creating an after insert trigger on your users table which creates the 100 orders – SE1986 Nov 11 '17 at 00:23
  • @SEarle1986 thank you I will do that! – Kevin Danikowski Nov 11 '17 at 00:28

1 Answers1

1

Can we have a order and sub order kind of concept introduced in database .

If you know that customer is going to order all 100 items , why not create a parent order id for that customer .

When customer checkouts he would have option to edit the number of items in bag .

After customer orders we can create suborder id kind of thing for each item referring to number of items in each order with other meta details .

This would eventually lead to reduction of time in customer sign up and sub order id could be further delayed . This would also lead to reduction of unused data in case customer does not checkouts . 100 rows would be then reduced to 1 .

yathartha
  • 472
  • 5
  • 8