Adding, editing or deleting rows

My app is about managing your expenses. It has a table called EXPENSES and when a user registers an expense, he/she chooses a category and subcategory (for example FOOD and then SUPERMARKET or RESTAURANT, etc). I have pre-populated CATEGORY and SUBCATEGORY tables, with all the corresponding relations between tables. The user can edit or delete a category or subcategory (only when there are still no expenses related to it). Or even add a category/subcategory. Here is the problem: to show the default categories/subcategories to all users, the columns cannot be user-specific. But when a user chooses to edit/delete a category/subcategory, I wish the columns would be user-specific so that it does not affect other users. When adding a category, I could populate a UserID column so only this user can see his new category. But what can I do when the user edits or deletes?

Normally I would recommend row owners, but you can’t mix rows under row ownership with rows that are not. A way around it is to utilize Roles and give each user the same role, but that’s different can of worms.

I think what I would do is add a column to your category and sub category tables to hold a User’s RowID value. So when the user adds a category or sub category, you also write the row id from the user profile to those tables.

So ultimately, you would filter your choice components to only show items where the user’s ID is empty (default options) OR matches the RowID in the user profile (user’s options).

What you suggest would solve the problem when user ADDS a category. But it doesn´t when user deletes or edits a category, right?

Yes the ID would be written when they ADD a category.

Why do you think it would be a problem if they edit or delete the category they created and is only visible to them? It’s their category. The ID never changes, so the row is linked to them until they delete it.

It would not be a problem if they edit or delete the category THEY created. But it would be a problem if they edit or delete the default categories (the categories that already come with the app). Right?

Don’t let them edit the default categories. You can easily condition the edit button so it’s only visible on categories they created, or only show them a collection of their own categories.

1 Like

OK, that´s a decent alternative. I wont let them edit or delete the default categories. Just the ones they create. Thanks!!!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.