Adding reference fields

Let’s say we ask the user a question with a dropdown that connects to the tiles from another database. In this case Destination, I want to record Name and Date into dataset1 as text, and Destination is a reference field that I want to link to the record in Dataset2.

For example: if the user answers destination Tel Aviv then the record is created and the field Destination (reference) is referenced to Tel Aviv.

➜ Text field to store in “dataset1”

➜ date field to store in “dataset1”

➜ Dropdown with titles form " Dataset2" to store in “dataset1” reference to “Dataset2”

import wixData from 'wix-data';

// ...

let countryItem = // get country item from somewhere

let toInsert = {
  "title":        "Mr.",
  "first_name":   "John",
  "last_name":    "Doe",
  "country":      countryItem
};

wixData.insert("myCollection", toInsert)
  .then( (results) => {
    let item = results; //see item below
  } )
  .catch( (err) => {
    let errorMsg = err;
  } );

/*  item is:
 *
 *  {
 *    "_id":          "rifk4nrk-dj4o-djhe-oidk-fnoqw4oiglk4i",
 *    "_owner":       "ffdkj9c2-df8g-f9ke-lk98-4kjhfr89keedb",
 *    "_createdDate": "2017-05-24T12:33:18.938Z",
 *    "_updatedDate": "2017-05-24T12:33:18.938Z",
 *    "title":        "Mr.",
 *    "first_name":   "John",
 *    "last_name":    "Doe",
 *    "country":      "id-of-usa-item"
 *  }
 */


hi Carlos,

See this thread