Hi, people!
I’m building a petition site and trying to figure out the best solution to use the collections. My site will have multiple different petitions, created by the users. So I think I’ll need 1) one collection to store users profiles; 2) one collection to store the petitions.
But then I don’t know the best way to store the data of what petitions each user signed.
a) Should I create a new collection storing the petition names and the users who signed each one? Or this could result in a collection with too many columns to work with?
b) Should I create an individual collection for each petition? But how can I do that automatically, as the petitions will be user generated?
c) Should I, instead of creating a third collection, build somehow a correlation between collection 1) and 2)? How?
Consider that the data must be stored in a way that I can retrieve the information later and be able to communicate with users, example: send emails to everyone who signed an specific petition.
Thank you in advance!
Daniel
Hi Daniel!
Generating collections automatically is not something that’s possible with Wix for now but what you can do is use 2 different collections -
The first would be ‘petitions’ collection which will contain all the different petitions (distinguished by number (for example) in order to make it simple. A.K.A - petition 1, petition 2 etc…).
In this collection you can also add columns for description and whatever data you want to gather/show.
The second would be ‘signs’ collection. In this collection you’ll store all the signs provided by users (for all petitions). Since you marked every petition with a unique key (number, title - you name it) you can now use a simple query to retrieve the data in any way you wish to (for example - if you’d like to present all the signs on petition 4, use a query that will search the collection for all results that their petition number is:
.eq("petition", "4")
Now, my suggestion (assuming that you accept the rest of my answer :P) is that you’ll use the numbering column as a reference field.
That way you can create a correlation between the two collections and match the data between them.
I hope that works for you.
Let me know if it doesn’t!
Doron.
Hi, Doron! Thank you for the answer! I think that will work!
By the way, if I want to allow the user to rate the petition, how can I correlate a rating to a petition in a query? Considering that a row in the Signs collection will be like: john@doe.com; Petition 1; rate 2; Petition 7; rate 5; Which means that user John signed Petition 1 and gave it a rate of 2 stars.
Example: I want to show all the users that signed the Petition 1 and rated it with 5 stars. How to query it? Or should I build the columns in this collection differently?
Hi again!
Yes! Adding a column for rating should do the trick.
Later you can use WixDataQuery ‘.eq()’ in order to retrieve the relevant items according to the filtering you want.
Let me know if it worked for you.
Doron.