- Goal:
My goal is to insert several rows at once into a table with the data coming from a checkbox group. The data to be submitted are the checkboxes that are selected. Each new row contains three pieces of information which also are the three columns aside from the primary key in the target table.
(1) a business_id from localstorage
(2) a meal_type_id (int not null)
(3) a meal_type_variation_id (int not null)
The target table is called business_x_meal_type_variation
- Steps:
I feel like I've tried everything that I know of and can Google my way to and even ChatGPT haven't been able to do the trick. I have not tried JS yet, because I don't know how to write the code.
This here is the setup.
Basically, for a given restaurant, if it serves either or all of the four meal types I'll check off their respective checkbox revealing a set of possible variations.
Let's say I've checked off the variations for Breakfast as in the image.
This means that the restaurant
(1) Serves breakfast.
(2) Serves gluten-free, vegan and vegetarian breakfast.
I want to insert three rows into my table.
The business_id is the same for each row.
The meal_type_id is the same for each row.
The meal_type_variation_id depends on the variation chosen.
In Retool, selecting those three values also means there are 6 values that are NULL values which the latter column wont accept (to avoid having e.g. breakfast written in there without variation multiple times).
I obtain the business_id using {{fetchLocalStorageBusinessId.data}}. That works perfectly fine.
If I make a query for each of the four types of meals, the meal_type_id can simply be 1, 2, 3, and 4 for each of the four queries.
Getting a query to first read which of the four types (breakfast, brunch, lunch, dinner) are selected and then which variations within each of those would be the ideal scenario.
In that case, I can obtain the meal_type_id using SELECT * FROM menu_meal_type
That table only contains meal_type_id and name as below:
1 breakfast
2 brunch
3 lunch
4 dinner
Final piece of information. For the four meal-type checkboxes, in the beginning, I had them shown using the query above. But then since it's always going to be the same four values and to simplify my attempt at inserting the records, I made them into four separate checkboxes and simply name them using a label.
I hope this covers all necessary information without also being too confusing. Basically, how do I insert records from a checkbox group but only the ones selected while ignoring the rest.
Thank you so much