If you have a 1-n relationship setup and query the n-collection (holding ref to 1), then is it possible to WixDataQuery the 1-part too?
Example Collection layout:
Main: Date, Boolean, _id
Detail1 : SKU, Num, ref_toMain
Detail2 : SKU, Num, ref_toMain
Now, what I would like to do is this:
1)select Detail by SKU=“12345”
2)and select ref_toMain.Boolean = true
Is this possible? I have “included” (.include “ref_toMain”) in my queries, but can´t gt it working.
Hello @giri-zano ,
so this is not possible (to my knowledge) since ref_toMain is only an id when you make your request. It gets populate once the request is executed.
I would suggest using an afterUpdate hook that update a 4th field “mainBoolean” in the collection detail1 and detail2 so you can do the query in one operation
Yes, I believe you are right. It looks like the query is first executed and only after that, the .include() data is added, so not available at the moment of query.
I solved it in another way: looping thru the array and .splice everything where “mainBoolean” is not true.
Your solution could also work, but it introduces data de-normalization, which I am not fond of.
I find it strange that this type of join is not available in Corvid, since it is a very common one: e.g if you have back ordered products and the moment they arrive, you want a list of all those products from Orders, where in the main row OrderStatus=approved. This is a quite common query.
But anyway, thanks.