Back

(SOLVED) how to implement bookmarking functionality

  • 0
  • Flutter
  • Databases
  • Accounts
  • Self Hosted
  • Users
Faisal7
22 Dec, 2023, 15:31

i have locations collection and each user can bookmark some locations.

For that i created an another collection called bookmarks and their i have userID which is a relational attribute with many to one and a locations attribute which is also a relational attribute with many to many,

so retrieving all the bookmarks for a specific user is not a problem but i have a problem to get a specific bookmarked location if the user clicks on a location in app and see set the ion accordingly if its bookmarked or not and also want to know how to save and update a location in my collection if a user bookmark a location.

i would be very happy if anybody can give me some suggestion if this approach is good at all and to help me better understand the whole bookmarking a location and the database architecture for it. Thank you.

TL;DR
A user has implemented a bookmarking functionality using a separate table called "locationBookmarks" with userID and locations as relational attributes. They are experiencing two issues: they cannot perform queries on relational attributes and cannot retrieve a specific bookmarked location. Another idea they had is to create a separate document for each bookmarked location without relational attributes. They are seeking suggestions and guidance on the best approach for bookmarking functionality and the database architecture.
1976satch9
22 Dec, 2023, 15:44

hi i have problem with relation too

1976satch9
22 Dec, 2023, 15:45

can you share something about your problem?

Faisal7
22 Dec, 2023, 16:36

yes sure. I have implemented or try to implement a bookmarking of a location functionality. I have created a seperate table "locationBookmarks" their i have userID as relational attribute and a locations relational attribute. The problem what i have now that i cannot do any queries on relational attributes thats the one issue and the other issue is if i in general have relationship and somehow want to retrieve a specific bookmarked location i cannot do this at least i dont have any idea how. Overall i also want to know how i implement such functionality. Another idea i also had, that maybe i would have an another table locationBookmarks but without relational attributes just the ids of the locations and each time the user save a location to bookmark it will be a seperate document for that user and their will be then for example if the user bookmarked 10 locations their will be 10 documents with th same userIDs.

Ernest
22 Dec, 2023, 18:47

In your bookmarks collection did you set the relationship as Two-way? Doing so allows you to access data from either collection from the other. Personally, I'd go with your second approach of creating a locationBookmarks collection because there are some issues and limitations (queries) with appwrite relationships currently. You'd have to experiment with your use case though.

Faisal7
23 Dec, 2023, 10:55

no i used One-way relationship but yah you right i will go with second option. I still will have the relationship many to one, and can then also do queries on it, so every record in bookmark table will be an actual user and an actual location, but on user and one location pr document. That way by retrieving the DATA i will get the LOCATION and USER object instead of the ids just. I implemented and tested. It works fine, but i have still one issue which is when i toggle bookmark i just do normal document creation and deletion so its not responsive when clicking the bookmark. I dont know how to optimize it.

Muniraja
23 Dec, 2023, 20:41

@Faisal7 Dm me

D5
23 Dec, 2023, 21:31

From what I understand, in such case to try to get the document that has both the user ID and the doc ID. If you can get it they that means it's bookmarked. If you get 0 results, it's not

Faisal7
23 Dec, 2023, 21:50

yes exactly thats how i did with document creation and deletion which means bookmarkd or not bookmarked in my logic but i am checking for the location and userId if its empty or not.

Faisal7
23 Dec, 2023, 21:51

and i also optimized the delation of the bookmark icon changes. 😀

D5
24 Dec, 2023, 00:03

So from what I understand then is that you want it to respond basically instantly?

Faisal7
24 Dec, 2023, 10:12

basically yes if this were the good solution

Faisal7
24 Dec, 2023, 10:13

and it seem that this is the good solution for now i think.

D5
24 Dec, 2023, 10:23

Yes. Current solution is probably the best one. You could try not to get the related things for a faster response and also to give the sensation to user that it's instantly, do the request in the background and show it as bookmarked instantly

Faisal7
24 Dec, 2023, 13:58

yes i also do it like this. i instantly give the user feedback and change the icon accordingly and then do the backend operation as asyncronous and after that i check it again if the operation were succesfull the icon stays as it was and if the operation failed the icon comes to its original position for eaxmple.

Faisal7
25 Dec, 2023, 21:21

(SOLVED) how to implement bookmarking functionality

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more