Hello all, please forgive me if my question is too simple but I am trying to learn velo for developing my own website.
I’ve been reading the velo documentation and trying to understand the parameters in the WixData.queryReferenced()
function. The first parameter is the collection ID. That, I think I understand. But I am struggling with the second parameter - the “item” parameter, which is supposed to be a union (btw I have no idea what it is). The third parameter is the PropertyName and I belive it refers to the name of the multi-referenced field in the collection ID.
Can you please help me understand what the “item” parameter in queryReferenced refers to?
Below is an image of a sample collection with multi-reference fields. The collection has an ID “Printsizes”.
If I would like to do queryReferenced on this collection, I believe the first and third parameters should be “Printsizes” and “Printmaterial_2X3Sizes”, respectively e.g.,
WixData.queryReferenced("Printsizes", "item", "Printmaterial_2X3Sizes")
However, I have no clue what the second parameter “item” is. I wanted to access the first row and references in “Printmaterial_2X3Sizes” column, is the second parameter in queryReferenced just “4x6”?
Your help will be very much appreciated!
Hi, @user5208 !!
I read the official reference, and it states that item refers to “The referring item or referring item’s ID.” Looking into it further, it says that item can be either a String or an Object. I believe the String refers to the item’s ID, while the Object represents the item itself. Since it says either can be used, it means we can specify one or the other. Probably.
When retrieving items from a Wix collection, we usually fetch multiple items at once. In such cases, we receive an array containing multiple item objects. Each object in this array represents an item. In other words, each row in your collection corresponds to a single item, which is a single object. It looks something like this: { _id: "someitemId", ... }
.
So, in the function argument, you can specify either "someitemId"
(a string) or { _id: "someitemId", ... }
(an object). I believe that’s what it means. Apologies if I got anything wrong! 
HI @onemoretime,
Thank you for your reply. I guess my question is how do I know what the "someitemId"
is in order to reference it. The Velo doc does not really say what it should be.
The easiest way to check an item’s ID is to view it directly in the Wix collection. In the collection you’re looking at, you have fields like “Number” and “Size,” right? You can also display the “ID” field there. By default, it is hidden, so you need to make it visible first. You can probably do this by clicking the Manage Fields button, which will open a menu where you can choose which fields to display. 
@onemoretime Thank you so much! That has actually worked. When enabled the ID field in Six editor, then copied and pasted that ID in wixData.queryRefernced("Printsizes", "2bdd98b7-2a41-4a24-8455-c752f1802822", "Printmaterial_2X3Sizes")
it did return a single object with its id and title at the end but this is very inefficient I think. How about if I wanted to reference all items. I don’t think I need to copy and paste the ids of all items. There has to be another way to identify the item without that nasty looking string 
Sure, if we think about it straightforwardly without any fancy tricks, we could start by using a wix-data
query to fetch all the data from your collection, then extract just the _id
fields. After that, we could loop through and execute queryReferenced
, and finally combine the results to retrieve all the items (including the referenced ones). Personally, I’m not a big fan of multi-reference fields, so I’m not entirely sure if this approach is perfect. 