1 00:00:01,290 --> 00:00:04,590 Now that we've got this order status put together let's figure out what's going on with this ticket 2 00:00:04,620 --> 00:00:06,570 Doc reference right here. 3 00:00:06,570 --> 00:00:11,070 Remember we want to replicate all the different tickets that are being created inside of our ticket 4 00:00:11,070 --> 00:00:14,290 service over to the order service as well. 5 00:00:14,490 --> 00:00:19,230 Then on each of our different order documents we're going to provide a reference over to the ticket 6 00:00:19,230 --> 00:00:25,010 that this order is trying to allow a user to purchase so in just a moment we're going to create another 7 00:00:25,010 --> 00:00:26,690 model inside of our models directory. 8 00:00:26,690 --> 00:00:31,990 And this model is going to create this idea of a ticket inside of our order service. 9 00:00:32,020 --> 00:00:36,820 We're going to access these tickets and associate them with the orders through the population system 10 00:00:36,850 --> 00:00:39,240 or the reference system in mongoose. 11 00:00:39,250 --> 00:00:44,200 Let me very quickly give you an example of how that code or how that Mongoose stuff is going to work. 12 00:00:44,260 --> 00:00:47,040 So there's really three different scenarios we need to worry about here. 13 00:00:47,050 --> 00:00:51,460 I wrote out the three different scenarios in code rather than the diagram because diagram is kind of 14 00:00:51,460 --> 00:00:57,600 hard to understand when it comes to just strictly code and how we actually write the code out to the 15 00:00:57,600 --> 00:01:02,580 three things we need to understand how to do is how to associate an existing order and a ticket together 16 00:01:03,740 --> 00:01:09,810 to associate an existing ticket with a brand new order that is about to be created and then finally 17 00:01:10,110 --> 00:01:15,900 how to fetch an order from our database and the associated ticket that is whether or the ticket that 18 00:01:15,900 --> 00:01:17,590 is associated with it. 19 00:01:17,640 --> 00:01:21,870 So first case right here how do we associate a existing order and ticket together. 20 00:01:21,870 --> 00:01:24,770 Well we're going to pull a ticket in order out of the database. 21 00:01:24,840 --> 00:01:29,700 We're then going to take that ticket and set it on the ticket property of the order and then save the 22 00:01:29,700 --> 00:01:30,880 order to the database. 23 00:01:30,900 --> 00:01:31,580 That's pretty much it. 24 00:01:31,590 --> 00:01:38,880 That's how this ref system works with Mongoose if you want to associate an existing ticket with a new 25 00:01:38,880 --> 00:01:39,270 order. 26 00:01:39,300 --> 00:01:44,370 So this really very much is what we are about to do inside of our new route handler. 27 00:01:44,670 --> 00:01:46,750 We're going to pull the ticket out of the database. 28 00:01:46,800 --> 00:01:52,380 We're then going to try to build in order and for the ticket property we're going to assign the ticket 29 00:01:52,380 --> 00:01:54,370 that we just pulled out of the database. 30 00:01:54,560 --> 00:02:00,780 We would then save the order to the database like so. 31 00:02:00,940 --> 00:02:05,890 And then finally whenever we want to figure out what order is associated with what given ticket we'll 32 00:02:05,890 --> 00:02:07,430 do a query for an order. 33 00:02:07,540 --> 00:02:13,090 And on that query we're going to also add in this little populate method to it to a call populate provided 34 00:02:13,150 --> 00:02:16,690 the name of the record or the key on the order that we want to populate. 35 00:02:16,690 --> 00:02:20,860 In this case it is ticket as we are setting that ticket property right there. 36 00:02:20,940 --> 00:02:25,590 Then when Mongoose goes and finds this order inside the database it will also fetch the associate with 37 00:02:25,590 --> 00:02:27,120 ticket with it as well. 38 00:02:27,120 --> 00:02:33,570 And we can then access that ticket off of the order by writing out order dot ticket. 39 00:02:33,600 --> 00:02:38,730 So for example if we wanted to know the price of the ticket would you order ticket price if you wanted 40 00:02:38,730 --> 00:02:42,220 to know the title the ticket order that title that ticket. 41 00:02:42,240 --> 00:02:48,300 That's pretty much it so we get all this stuff working we've already set up the order itself correctly. 42 00:02:48,380 --> 00:02:52,250 We just have to also add in a new model or a ticket as well. 43 00:02:52,250 --> 00:02:53,220 That's pretty much it. 44 00:02:54,110 --> 00:02:55,390 So let's pause right here. 45 00:02:55,410 --> 00:02:58,220 We're going gonna come back the next video create a model for our ticket.