Perhaps this has been raised before, but I’d like to see reference fields make the referred to primary field value available through the wixData/wixDataset API. Just as the Data Manager resolves the ._id field to the primary field value it represents, we should be able to use this “alias” in code.
Why would this be useful?
First, to eliminate a lot of confusion in the user base about what a reference field really contains. Yes, it is all documented, but that does not make it any less confusing – especially when one can see the primary field value in the Data Manager.
Second, to eliminate data redundancy and potential errors. Because reference fields do not contain the referenced primary field value, one strategy is to redundantly store the referenced value in the referring collection. That way it can be used in filters, datasets, tables, code, etc. The problem is that the reference field and the redundantly stored primary field value can get out of sync if the programming is not done quite right. I hear you saying, “Why not use the .include() option to follow the reference and then capture the primary field that way?” Yes, that works if you are only trying to retrieve the value, but not if you are trying to use it to qualify the database search in the first place.
Third, to make data import and export a lot simpler, especially during testing. Often it is necessary to clear and then reload a table with new data. When collections are connected by reference fields, one has to get the referred to ._id value to populate the the referring reference field in another collection. Because these ._id values can change while the primary field value does not, it makes the import process quite tedious – not to mention having to be something of an Excel guru to do things efficiently. Imagine how simple life would be if we did not have to worry about the underlying ._id value and only our own data values.
I am well aware that there may be limitations to the Wix database engine that make this a lot harder than it seems, or that this is not a priority for the Wix Code team. But… if the Data Manager can do it, why can’t we?