Import Table with Column Reference

Hi, I’am italian sorry for my bad english…
Whenever I add a table (import) to my site, I always have to manually enter the columns with the referenced fields to other tables also imported.
Is there an alternative fast way ?

Thanks

Hi,

please have a look at https://www.wix.com/code/reference/wix-data.Hooks.html#beforeInsert
just before the item insert, change the reference value to the _id of the item it references

Shlomi

Hi,

If you have 2 collections and they have a master-detail relationship, you can do the following:

Import the details collection, but make sure you specify which of your columns contain IDs.

Then, import the master collection, and map the right column as reference to details collection and make sure that in that column you store the same IDs used during import of details collection.

You can have a look at our help center article: CMS (Formerly Content Manager): Importing Content into a Collection | Help Center | Wix.com

Good luck,
Idan.

Thanks, one more question.

“Import the details collection, but make sure you specify which of your columns contain IDs.”

Is the column that must contain ID an existing column in the collection (primary field for example) or
ID column that normally is not displayed (in Visible Fields )?

Thank you
Claudio

Hi Claudio,

when you import the data, please import the key into the _id column which is hidden by default, in the referencing collection, the reference column actually points to that

for example:
collection1 - countries
_id(hidden by default): should contain the country key like it appears in your import csv
title

collection2 - cities
title
country (ref, should contain the same data as in the country (_id) column)

please let me know if you need further assistance
thanks,
Shlomi

Hi Shlomi,
I tried to follow your instructions, but there’s an error:

Thanks for interesting
Claudio

Hi Claudio,

Can you please share the schema of your 2 collections, and a few lines of your csv?
Or even create a simple example to demonstrate the issue?

Shlomi

Hi Slhomi, for example

collection1 TEAM

“CAMPIONATO”;“SQUADRA”;“SERIEPOS”;“SERIENEG”
“ITA”;“INTER”;3;5
“ITA”;“NAPOLI”;4;6
“ITA”;“JUVENTUS”;0;7

collection2 CLASSIFICA

“SQUADRA”;“PUNTI”;“VINTE”;“NULLE”;“PERSE”
“INTER”;44;3;5;2
“NAPOLI”;34;4;6;5
“JUVENTUS”;56;2;7;3

I want the two fields “SQUADRA” of the collectio1 and collection2 to be referenced to each other.

I hope you’ll understand me

thank you

Hi,

What do you mean by reference each other?
normally you will want one collection to reference another.
Can you also share the data type of each column in your collections?
Why did you choose this collection structure?

Shlomi

Hi, ok sorry you are right.
I want one collection to reference another, but when I try to import the first csv file, the error still here.

Claudio

Hey Claudio,

i need your help to create the exact same scenario you are facing. can you maybe share the url of the site you are trying to build, i’ll have a look to better understand

thanks,
Shlomi

ok

Iis that ok?

The “SQUADRA” field in collection SQUADRE, has to reference to the “SQUADRA” field in the CLASSIFICA collection.

Thanks,
Claudio

Hi Claudio,

  1. it means that the SQUADRA field in collection SQUADRE should be of type “reference” not of type string!
  2. in CLASSIFICA collection you need to hold the data which now exists in the field “SQUADRA” also in the hidden filed which is called ID (when used in code it is also referenced as ‘_id’)

only then import the data into the collections,
good luck!
Shlomi

Hi Shlomi,
this is the problem. I cannot to hold the data which now exists in the field “SQUADRA” because I have to import the csv file each time when i needs it.
Anyway I thank you for your help, you have been very kind. I will solve in another way.

Thanks again
Claudio