Link Search Menu Expand Document

Reference Field

Table of contents

  1. Example Usage
  2. Allowed Attributes
    1. Default
    2. Required
    3. Custom Name
    4. Auto Load
    5. Example Usage

A DocumentReference refers to a document location in a Firestore database and can be used to write, read, or listen to the location. The document at the referenced location may or may not exist.

Example Usage

const {Model, Field} = require("fireo");

class Company extends Model{
    name = Field.Text();
}

class Employee extends Model{
    name = Field.Text();
    company = Field.Reference();
}

const c = Company.init();
c.name = "Abc_company";
await c.save()

const e = Employee.init();
e.name = 'Employee Name';
e.company = c.key;
await e.save();

Allowed Attributes

The following attributes supported by Boolean Field.

  1. default
  2. required
  3. name
  4. autoLoad
  • Default

    Default value for field. This is base attribute that is available in all fields. Read More

  • Required

    Set true if value is required for the field. This is base attribute that is available in all fields. Read More

  • Custom Name

    Set different name in Firestore instead of field name. This is base attribute that is available in all fields. Read More

  • Auto Load

    Load reference document automatically, If you disable the auto_load then you can get document by get() method.

Example Usage

const {Model, Field} = require("fireo");

class Employee extends Model{
    name = Field.Text();
    company = Field.Reference({autoLoad: false});
}

const e = await Employee.collection.get({key: emp_key});
console.log(e.company);

// Reference document can be get using get() method
const com = e.company.get();
console.log(com.name)

Copyright © 2019 FireO All rights reserved. Powered by OctaByte