Home Reference Source
public class | source

Reference

Reference

A model representing a record reference in Skygear record.

Static Method Summary

Static Public Methods
public static

fromJSON(obj: Object): Reference

Deserializes Reference from a JSON object.

Constructor Summary

Public Constructor
public

constructor(recordOrRecordType: Record | String, recordID: String)

Constructs a new Reference object.

Member Summary

Public Members
public get

id: String

this get was deprecated. Use `recordType` and `recordID` instead.

ID of the referencing record in the deprecated format (i.e.

public get

recordID: String

ID of the referencing record.

public get

recordType: String

Type of the referencing record.

Method Summary

Public Methods
public

toJSON(): Object

Serializes Reference to a JSON object.

Static Public Methods

public static fromJSON(obj: Object): Reference source

Deserializes Reference from a JSON object.

Params:

NameTypeAttributeDescription
obj Object

the JSON object

Return:

Reference

a record reference

Public Constructors

public constructor(recordOrRecordType: Record | String, recordID: String) source

Constructs a new Reference object.

Params:

NameTypeAttributeDescription
recordOrRecordType Record | String

the referencing record or the record type

recordID String
  • optional

the referencing record ID

Example:

let record = new Record('note', {
    _recordType: 'note',
    _recordID: '123',
    content: 'hello world',
});
let ref = new Reference(record);
console.log('type', ref.recordType);  // note
console.log('id', ref.recordType);    // 123
let ref = new Reference('note', '123');
console.log('type', ref.recordType);  // note
console.log('id', ref.recordType);    // 123
// WARNING: This usage is deprecated
let ref = new Reference('note/123');
console.log('type', ref.recordType);  // note
console.log('id', ref.recordType);    // 123

Public Members

public get id: String source

this get was deprecated. Use `recordType` and `recordID` instead.

ID of the referencing record in the deprecated format (i.e. type/id).

public get recordID: String source

ID of the referencing record.

public get recordType: String source

Type of the referencing record.

Public Methods

public toJSON(): Object source

Serializes Reference to a JSON object.

Return:

Object

the JSON object