Hi
I have a members site and have created a database for artists profiles (profile), I then have a second database for posts (posts) this contains a reference field for the artists profile.
When adding a new post to the posts dataset I would like members to be able to choose their artist profile to attach to the post using a dropdown. My problem is the dropdown is showing all the artists profile entries in the dropdown so how do I filter it to just show the profiles owned by the logged in user using code?
I am pretty new to this so any help would be very much appreciated.
Hi there!
Depending on how you would like to populate your dropdown you can use the following options.
A - Populating your dropdown using $w.Dropdown.options
Run a wixData.query() on the Collection with the Artist Profiles. Use .eq on the “_owner” property to match with the currently logged in members id. Populate the dropdown using these results.
B - Using a dataset
Add a dataset to the dropdown for the Artist Profiles. You can either add a filter using setFilter() when the page loads to check if each artist is associated to the logged in member using the “_owner” property or use the options on the editor.
Hiya, any chance you can elaborate on the first option please?
A - Populating your dropdown using $w.Dropdown.options
Run a wixData.query() on the Collection with the Artist Profiles. Use .eq on the “_owner” property to match with the currently logged in members id. Populate the dropdown using these results.
Going this way → This would be just 50% of the truth from my point of view.
The problem would be that you would have to scan your whole DATABASE to be able to include all RESULTS from your DATABASE inside your query.
Even if you setup your limit to —> 1000, you still would need to expand your code, for example generating a function which would scan in several CHUNKS of 1000-items trough all your data (in this case let it be 3000-items).
Yes of course there are several solutions for it. I just wanted to mention it.
—> promiseAll() → parralel running-mode → fast
—> while-Loop (skip + limit - loop) —> serial-mode (takes some time)
—> hidden solution called —> ( iQuery ) ← sorry for Velo-Ninja nonly → an intelligent query, which do all the stuff on its own, without having to take care about it
Don’t forget, you will need to scan whole database to be able to provide your wished results inside of your DROPDOWN. Not doing this, you would provide your customers just a part of data.
However the disatvantage of this solution, is the delay-time to load DropDown with full data. The bigger your data, the more you will have to scan → the more time-delay for loading your dropdown.