Hello guys,
The title says it all really.
All I am trying to do, is use member ID as a reference field in another collection.
Hello guys,
The title says it all really.
All I am trying to do, is use member ID as a reference field in another collection.
Surely someone knows the answer to this.
Assuming the answer is āNo, you cantā, as it seems that way ā¦ why would you not make the ID, which is always a unique identifer, the primary key???
I must admit, I last worked in IT / Databases about 15 years ago, but we pretty much ALWAYS had the ID being the primary key. The only workaround I can see, to ensure my reference is unique, is to copy the ID field to the Title field every time a record is created, which just seems stupid.
Iām wondering the same thing. There is a system ID field as described here - CMS (Formerly Content Manager): About Your Collection Fields | Help Center | Wix.com. Iām brand new to WiX so Iām not sure if we should create our own ID field as you mentioned or use the system field
Hi Mike.
I do a lot with databases on daily basis. I understand the unique ID as a numeric value. Also I see tons of tables where we use a second column which is also unique. It depends what the data is really. Table with incidents for example, right I would certainly go for numbers, but tables with users I would not.
However, if I look at Wix, as a framework for websites, I also understand why they set a text field as a second (for the user first) primary key. The column you set to primary key is also the one used for the dynamic page (by default that is). SEO works better with meaningfull urls too. If I look at site data my self, I also see the point. Say you have articles. It will tell you more if the primary key is ānot possible to set id as primary fieldā (see this post url) then ā12311ā. Now my best practice I took designing my site is to use an abbreviation column as primary. I have trails with a name. I make them short like āCWUā for āCape Wrath Ultraā, the countries āen-sā for Scotland, ānlā for āthe Netherlandsā and the same for languages. I do have some refrence data too, like images. Here I just go for ācwu_001ā, ācwu_002ā and so on.
Maybe you can find a bit of your answer in my two cents.
thatās just hilarious I canāt even think of a reason why would they do that.
Jesus how dumb!
I know this is an old thread but can hopefully help someone.
First create a new column which will be the copy of the ID. I created and named it āprimaryIdā in my collection.
Then, you can use hooks. Checkout how to add one here
Create a ābeforeInsertā hook on the wanted collection.
Once it is created, this is the code:
// The function name and signature is generated automatically
export function {your_collection_name}_beforeInsert(item, context) {
/* Wix doesn't allow system id `item._id` to be primary key (dumb, I know). That's why we map it to a newly created column `primaryId`
*/
item.primaryId = item._id; // primaryId must be the name of the column you created
}
Now, make the primaryId column as primary by clicking `Make Primaryā in the
collection and now your primary column will be the primaryId.