#Building a reservation system
21 messages · Page 1 of 1 (latest)
yes, how should that constraint be enforced since it should not be done in the models?
There are at least 2 approaches that come to mind. Just thinking through the requirements...
By going with an FK for previous reservation you're creating a chain of reservations. I'm not sure that's the ideal model design...
Looking at this I'd take a step back and think about requirements and what happens in the real-world...
Assuming that a customer can have many reservations with a hotel, then perhaps the relationship might make sense as:
- The org has many properties.
- The customer can rent any number of properties.
- I assume that a customer can only rent one property at a time.
- You want to track all rentals over time by a customer.
Does that sound correct?
There should only be those 2 models
This, dear community member, is a useful mindset to take into development. It really helps to write out what you're trying to accomplish, to analyze the processes/procedures before designing the data model schema.
From the above, you can then dive into how to think about the model. You might want to consider the following tables
- each Property
- can have many Reservations
- each property can be reserved by 1 Customer/Renter at a time...
I will give you that it sounds more logical but I saw this online and the solution should work only with those 2 models.
It does not have to be through a FK it can be set in the view
Hmmm...not sure I understand what you mean there. If you want to store data, and have related data elements, then you'll need to design the data model, and then CRUD through the view (Create-Read-Update-Delete) (or API)
Not all tutorials are equal. Might I suggest a video tutorial by Corey Schafer on YouTube. It will get you learning the concepts in a much more sensible way. The danger with following this tutorial is that it causes more confusion than is necessary. It's a very bad choice of tutorial topic.
Thanks for the recommendation, I'll take a look. Do you also think a good workaround for using only 2 models would be to use html tables ?
My brain works in a way where I need to understand what the problem is, and then I work out the approach. What problem are you trying to solve?
I would say the solution works if the data is displayed as in the tables on the picture. Perhaps the necessary data can be extracted from the 2 models and manipulated to be shown on the html tables like in the picture
I'd rename the field previous_reservation to reservation and move it over to the Rentals table. Then, I'd focus on a list view for rentals showing the list of reservations by querying for all reservations with a reservation FK matching the Rental.
The idea behind that is that a Rental (one) can have (many) Reservations ...thus one to many. Does that make sense?
I will try it
Good luck 🙂