Should I create a separate table for saved / favourited posts?

I am creating a property app where users can view properties listed for sale. I have a Listings collection and a Users collection. So far so good.

What I am stuck in is how to save “favourites”. This would be a feature where a user wants to save a listing for later view.

It doesnt seem to make sense to save this in the User collection because every time they save a listing, another duplicate record would need to be created with the same fields except the saved listing.It doesnt seem to make sense to save this in the Listing collection because then it would be duplicate records except the saved user field.

I can only think of one other option which is to create a Saved Listings collection where everytime any user presses “save”, it creates a record. So there would be a huge number of records. But it doesnt really feel like it is proper database design.

Any recommendations

On your listing database, add a new relationship property. Link it to your users database and set it as “Many to Many”. Call it something like “Favourite”

On the editor, add an icon to your listing page. This will be your “favourite” button.

Set an action on the icon to UPDATE when clicked, “add logged in user” to the “favourite” property.

You’ll need 2 icons, one to add to favourites and one to remove from favourites. Assign conditional visibility so that they only show if the user has or hasn’t favourited the listing.

2 Likes

Thank you diegozane. How would this work when another user favourited the listing? It would either (1) need to create a new record to accomodate the new user or (2) replace the current user’s details. Since #2 would lose the current user’s details, that wouldnt work.

I was hoping for a solution where there would be only one record per listing but sounds like it may be unavoidable?

Because it’s a Many to Many relationship, there isn’t a limit to how many people can favourite the listing. It’s not creating a new record, it’s linking the user to the listing. I have the same setup on my app and it works fine.

Ok thank you. I will try it out.

Hi diegozane, I have just gotten around to implementing this and it worked magically. Seems like Adalo sorted it out on its own by creating an array type data field. Anyway thanks heaps!

1 Like