Filter table based on another table

Got something cool to share with AppGini users? Feel free to post it here!
Post Reply
User avatar
D Oliveira
AppGini Super Hero
AppGini Super Hero
Posts: 347
Joined: 2018-03-04 09:30
Location: David

Filter table based on another table

Post by D Oliveira » 2020-10-30 02:40

Hi fellow Appgineers

Lets say a user is looking at a table 'recipes' and he finds one that he likes, to prevent the trouble of always searching for this recipe he wants to favorite this recipe, how would you go about setting that up? I can't create a favorite field and mark that recipe record as his favorite because other members might wanna favorite that same recipe too, would yo create a separate table to keep track of all favorite recipes? and even then how would you filter table 'recipes' just to show his favorites given that you're filtering the table 'recipes' using 'favorited' table data, any help is appreciated, thank you.

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Filter table based on another table

Post by pbottcher » 2020-10-30 21:32

Hi David,

maybe one idea is:

Create a table to the favorits with a field for the pk of your recipe and a field for the user.
Add a field to the recipe for the favorite selection.

Once the user selects the favorite field and stores the record, store the information in the favorits table and set the favorite field in the recipe record to "false/unset".

Use the hooks to handle the correct actions according to what the user does (select/unselect the favorite field),

Next you need to adjust the TV to reflect the correct favorite per recipe for the use. To do so, expand the QueryFrom to join your favorite table. Also modify the QueryFieldsTV to catch the favorite set.

For the DetailView you need to check the favorite field if your SQL query for that record and user returns match in the favorite table.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

User avatar
D Oliveira
AppGini Super Hero
AppGini Super Hero
Posts: 347
Joined: 2018-03-04 09:30
Location: David

Re: Filter table based on another table

Post by D Oliveira » 2020-10-31 02:13

Thank you for your insightful feedback, I ended up going with the simpler route, I created a mirror table, so when the user favorites a recipe, the recipe record is inserted in this new table with the ownership given to the user, so that I have multiple copies of that same recipe on the new table but with proper ownerships , then in admin area set new table for the user to see only the records he owns and there we have it :D

Post Reply