Database Reference Data

Hi!

Is it possible to write data to multiple database collections using a single form? I have one collection that collects the data for a family. I then want to use a separate collection to capture the first name and age for each member of the family.

Thanks,
Peter

Hi Peter ,

To achieve that, you have to insert the values to the database by code - Not by connecting the form to the dataset - . So, you can use wix-data > insert(), for more information on how to use it, check this out - Here

so your code should look something like this:

export function submitt_click(event) {

 let familyInsert = {
 "f1":   $w("#input1").value,
 "f2":    $w("#input2").value,
 'familyName': $w("#input3").value
};

let namesInsert = {
 "f1":   $w("#input1").value,
 "f2":    $w("#input2").value
}
wixData.insert("users", familyInsert)
  .then( (results) => {
 let item = results;
    wixData.insert('test',namesInsert);
  } )
  .catch( (err) => {
 let errorMsg = err;
  } );


}

Hope this helps!
Best,

Mustafa

Hi Mustafa, do you have experience with UPDATING DB SELECTION WITH DATA FROM EXTERNAL SQL DB

Hi Peter,

This is my suggestion:

  1. Create a database with the fields “first name” and “age”.

  2. Create a second database that include the rest of the data from the form and also a reference field to the first database. (By using reference filed you can avoid duplicated )
    Here you can read more about reference field.

  3. Use code to insert the first object to the first database (name and age) and after that insert the second object with the reference item to the second database.
    Here you can read about insert() function.
    Here you can read about insertReference() function.

Best of luck!
Sapir,