Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change how menu items relate to orders and order items #112

Open
albinantti opened this issue Jul 5, 2021 · 1 comment
Open

Change how menu items relate to orders and order items #112

albinantti opened this issue Jul 5, 2021 · 1 comment
Assignees
Labels
DISCUSS Topics of discussion Suggestion

Comments

@albinantti
Copy link
Member

Whilst we're already on the topic of drastically changing the database:

As it stands, rows in the OrderItem table (e.g. 1x hamburger (no onion) belonging to order no. 23) contains a menu attribute, which is a foreign key pointing to an entry in the MenuItem table instead of it being just a string with the name of the menu items.

This was chosen, IIRC, primarily to reduce the size of the order items table as it would without a doubt be the fastest growing table. It would also make changing menu items cleaner, provide some kind of consistency to keeping statistics (use the same hamburger menu item for several events etc), and make compiling statistics a lot easier, since there'd be no need to match strings.

This choice came with a following design choice to make, however, namely what should happen if a menu item is deleted?
Should we:

1. Delete the OrderItem row completely (as it is done now)?

Easy and clean, but deletes data from long-term statistics if users don't use the active attribute of a menu item enough. The current implementation of the menu item foreign key also means that empty orders can and do exist, since we don't periodically check the database for empty orders.

2. Set the OrderItem's menu attribute to NULL?

Also very easy and clean, but might ruin long-term statistics (it will count and display what quantity of Undefined has been ordered). Might preserve an indication of what type of menu item it was, since a row would change to 1x Undefined (no onion) to order no. 23. Also means we would have to allow the foreign key to be nullable, which would mean we could potentially create empty order item rows from the get-go.

Both these two alternatives also raise the question of whether or not we event want to save orders that are either empty or full of undefined items, or should just remove everything. What do we do with orders that contain 1x hamburger and 1x undefined?

3. Set the value to a default menu item of ID 0?

Essentially the same solution as no. 2, but without having to deal with NULL and setting the attribute to nullable.

4. DGAF about using foreign keys and instead save the respective menu item's name attribute as a string?

Would also probably be quite easy to implement using a get_name-function. Would preserve orders in the database better over time, but is this even something we want or should we put that responsibility on the users instead? Would also mean a larger table byte-size and would make comparing a little bit more annoying with string literals instead of matching numerical ID:s.

Perhaps we could discuss this a bit after the vacations? @dakaza98

class OrderItem(models.Model):
    id = models.AutoField(primary_key=True)
    menu = models.ForeignKey(
        to=MenuItem,
        on_delete=models.CASCADE,
        verbose_name=_('menu item'),
        help_text=_('Which item that was ordered.'),
    )
@albinantti albinantti added Suggestion DISCUSS Topics of discussion labels Jul 5, 2021
@albinantti albinantti self-assigned this Jul 5, 2021
@dakaza98
Copy link
Member

Discussion after vacation sounds good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DISCUSS Topics of discussion Suggestion
Projects
None yet
Development

No branches or pull requests

2 participants