Reference field

about the reference fields: Are we required to use that mini dropdown manually in each cell, or can we use the already filled fields of some column? …Imagine a first database with 10,000 animals and a description of each animal. Imagine a second database with the same 10,000 animals and their respective countries of origin … Now I want to create a dynamic page showing the animal, the description, and the country of origin … we will only be able to do this by manually filling 10,000 fields reference linking one by one? or is there an easier way ???(view column3)

database 1:
Column1: Animal (primary field) |
column2: description

database 2:
Column1: country (primary field) |
Column2: animal
Column3: (reference field: database 1 animal)

Hi Leandro,

are you using the import capability to create the 10k records in the collection you mentioned? are you using code to create your data in the collection? can you please share some more context?

thanks,
Shlomi

Hi Shlomi :slight_smile:

10k is a metaphor … in ‘wix code help’ in the ‘how to create reference field’ tab shows how to link reference fields. The picture below shows that for each song, it is necessary to indicate MANUALLY who is the artist of each music (database artist) … In the same example, there being 100 songs for examples, it becomes necessary to link one by one in all 100 records ? or is there a way of mass editing, but fast?

Hi Leandro,

thanks for the additional info!
as my previous reply suggested there are a several options:

  1. you manually create your data and thus while adding line by line you also use the above manual option you described
  2. use mass import/export options
  3. use code to apply the logic how, given a Song record, you decide which Artist is related to it : wix-data - Velo API Reference - Wix.com
  4. use a form with user data to create those records, allow a user to select or apply code as a part of the before insert hook

if you have an ability to code your selection over an existing large collection to which you want to apply a related field i’d recommend option number 3 above. however to provide better answer can you please share the specific scenario? the above was indeed just a ‘metaphore’ or a generic example from the documentation. is there a specific site you are trying to build at the moment you can share?

thanks,
Shlomi

Leandro,

here is some more info you may find interesting Velo Tutorial: Importing and Exporting Collection Data with Code | Help Center | Wix.com

Shlomi

Real scenario:
The course receives contacts from various sources such as Facebook, whatsapp, Instagram, website, and etc … The idea is to create a database to manually register those leads. (front-end)… So, I created a form page linked to the database “leads register”.

Page: LEADS REGISTER (link dataset: leads register database)

Code Lead: [130 ]
Name: [Bruce Waybe ]
Date: [12/01/2017 ]
Source: [Whatsapp Received ]
Phone: [219999999999 ]

        ||Submit button|| 

Imagine we get 100 leads from multiple sources and only 20 are really interested. In this case, it will be entered in the database “waiting list” or database “active students”

The interested Bruce Wayne would like to start class in the class on Saturday morning, but at the moment we are without a vacancy, so I’ll use the ‘waiting list’ page linked to the database 'waiting list"

Page: WAITING LIST (link dataset: wainting list database)

Code Lead: [130 ]
Class: [Saturday - Morning ]

||Submit button|| 

Now, I’m going to create a Dynamic tTable that shows all the codes that are on the waiting list specifically for Saturday morning class using filter.

Dynamic table:

[{Code lead}][{class }]
[ 122 ] [ Saturday - Morning ]
[ 125 ] [ Saturday - Morning ]
[ 130 ] [ Saturday - Morning ]


Inside the table, I linked the field {code field} to be opened in a new dynamic page.
Imagine that I clicked on field 130


Edition Dynamic page:
(Dataset: Write-only)

Code Lead: [130 ]
Class: [ Saturday - Morning]
Name: [Bruce Waybe ]
Phone: [219999999999 ]

    ||Submit button|| 

the reference field between the 2 databases is the field ‘code field’

My question: Do I need to manually bind this reference field in the database “wainting list” to manually inform the wix that the code 130 from wainting list is the same as the 130 code from lead register?

I need to create an editable dynamic page that retrieves data from 2 or more database

Hi, thanks for taking the time to explain this. The reference is made during the schema definition. You do not have to make the link manually.

When creating the lead record (130) and setting it to the lead table and then course table with a reference to the lead set the same key 130 as value using wix-data insert api or creating a matching registration form with a course dropdown with a pre insert hook to determine the status based on vacancy

So once you have the lead in context, you have the following details:
Lead name and info, the course he is interested in (thus its id) and the status to be set based on vacancy. Then as a good coding practice to separate the data model from your view layer once you have the data you create the matching db records

Please let me know if you will need further assistance with the actual code or dv collection schema. If so please also share the site url you are trying to build

Good luck!
Shlomi

Hi Leandro,

You can also type or paste the value you want in a reference field. If you input a value that does not appear in the referenced collection, the field will remain blank.

Thank you for raising this issue. I will update the article accordingly.

Sharon

Thank you Shlomi. I’ll ask a programmer friend to help me with option 3 … thank you very much

Thank you also Sharon. … If I could, I would give a suggestion for wix to create “reference columns” enabled to be a dynamic column type within the database. These columns would be just a mirror of some original column

Hii

I’d like to communicate that I have been able to link multiple fields. I exported the id field to excel, copied, and imported the same id in the reference column.

Leandro,
thanks for the update! and good luck Wix Coding!
Obrigado,
Shlomi

Are you doing this process every time a student gets registered? or does it update automatically after you do it once? I have a similar issue that you do, but I do not want to export/import data every day when users enter/update data.