new Object(uid){Object}
Name | Type | Description |
---|---|---|
uid |
String | object | The uid of this object or an object with initial values |
Example
//'blt5d4sample2633b' is a dummy Application API key
// Class('class_name').Object returns a Object constructor
// 'project' is a uid of a class on Built.io Backend
// 'blt12sampleb09157' is uid of an object on Built.io Backend
var Project = Built.App('blt5d4sample2633b').Class('project').Object;
// Example demonstrate constructor taking an object's uid as argument
var obj = Project('blt12sampleb09157');
// Example demonstrate constructor taking an initial value
var obj = Project({
name:'abc',
email:['abc@email.com','pqr@email.com']
});
Methods
-
staticObject.BackboneCollection(config, model){Backbone}
object.js, line 1347 -
Returns a Backbone collection
Name Type Description config
object Takes a plain JavaScript object where "objects" key is used to pass array of objects and "query" key is used to specify a query. model
Model Takes a Backbone model to be used by the collection for conversion. (If null is specified Built's default Backbone model is used) Returns:
a BackBone object
Example
//'blt5d4sample2633b' is a dummy Application API key // Class('class_name').Object returns a Object constructor // 'project' is a uid of a class on Built.io Backend // 'blt12sampleb09157' is uid of an object on Built.io Backend var app = Built.App('blt5d4sample2633b'); var Project = app.Class('project').Object; var Query = app.Class('project').Query; var project = Project({ username:'Super Project #41!' }); var project1 = Project({ username:'Super Project #41!' }); var projectArray = [project,project1]; var model = Backbone.Model.extend({ getName:function(){ this.get("username"); }, setName:function(name){ this.set("username", name); }, idAttribute:"uid" }); var backbone = Project.BackboneCollection({ objects : projectArray, model : model }); // Converts the objects in projectArray to Backbone collection using the given model var query = Query() .where('username','Super Project #41!'); var backbone = Project.BackboneCollection({ query : query, model : model }); // Query to Built.io Backend with given query and converts the returned objects to collection using the given model //Now backbone can be used to fetch, save, delete, update object on Built.io Backend. backbone.fetch();
-
staticObject.off(event, callback){Object}
realtime.js, line 1666 -
[Only avaliable with realtime plugin]
This function unregisters a single or all event listener(s) from Object constructor.Name Type Description event
String The event whose listener needs to be unregistered [Optional] callback
function The callback function used while registering [Optional] Throws:
-
new Error('Callback function to be removed is missing')
-
new Error('Event name is missing');
Example
// 'blt5d4sample2633b' is a dummy Application API key // app.Class('class_name').Object returns a 'Object' constructor var app = Built.App('blt5d4sample2633b').enableRealtime(); var Person = app.Class('person').Object; function cb(data){ console.log(data); } // Sets up a listener for create event Person.on('delete',cb); // Sets up a listener for broadcast event Person.on('broadcast',cb); // Specifically removes the delete listener Person.off('delete',cb); // Removes all callbacks attached for delete event on this resource Person.off('delete'); // Throws "Event name is missing" Person.off(cb) // Removes all listeners on Person class Person.off();
-
-
staticObject.on(event, callback){Object}
realtime.js, line 1133 -
[Only avaliable with realtime plugin]
This function registers an event listener on Object constructor.Given below is the list of supported events.
- Create
- Update
- Delete
- Broadcast
The 'create' event is triggered when a new object is created in the class with which the Object constructor is associated. Registered callback is invoked with the created object.
Update event is triggered when any object in the class with which the Object constructor is associated is modified. Registered callback is invoked with the updated object.
Delete event is triggered when any object in the class with which the Object constructor is associated is deleted. Registered callback is invoked with the deleted object.
Broadcast event is triggered when a message is broadcast for all objects belonging to a particular class. Registered callback is invoked with the broadcasted message.
Name Type Description event
String The event on which the listener should be registered callback
function The callback function to be invoked on event trigger Example
// 'blt5d4sample2633b' is a dummy Application API key // app.Class('class_name').Object() returns a 'Object' constructor var app = Built.App('blt5d4sample2633b').enableRealtime(); var Person = app.Class('person').Object; Person.on('create', function(person) { // created person object }); Person.on('update', function(person) { // updated person object }); Person.on('delete', function(person) { // deleted person object }); Person.on('broadcast', function(message) { // The message is broadcasted to all objects of person class });
-
addGroup(group){Object}
object.js, line 594 -
Adds a group field
Name Type Description group
Built.Group | Built.GroupMultiple Instance of Built.Group or Built.GroupMultiple Example
//'blt5d4sample2633b' is a dummy Application API key // Class('class_name').Object returns a Object constructor // 'details' is a group field in bug class var app = Built.App('blt5d4sample2633b'); var Bugs = app.Class('bugs').Object; var bug = Bugs(); // Consider 'bugs' class has a group field 'details' which contains a reference field 'project' var details = Built.Group('details',{ title: 'UI bug' }) bug = bug.addGroup(details); bug.save() .then(function(bug){ console.log(bug.toJSON()) })
-
addQuery(key, object){Object}
object.js, line 821 -
Adds a custom query to the object
Name Type Description key
String Query parameter's name object
Variable Query parameter's value Example
//'blt5d4sample2633b' is a dummy Application API key // Class('class_name').Object returns a Object constructor // 'project' is a uid of a class on Built.io Backend // 'blt12sampleb09157' is uid of an object on Built.io Backend var project = Built.App('blt5d4sample2633b').Class('project') .Object('blt12sampleb09157'); project = project.addQuery('include_owner',true); project.fetch() .then(function(object){ // do something });
-
assign(data){Object}
object.js, line 246 -
Assigns parameters to the object
Name Type Description data
object Plain JavaScript object with new contents Example
//'blt5d4sample2633b' is a dummy Application API key // Class('class_name').Object returns a Object constructor // 'project' is a uid of a class on Built.io Backend var Project = Built.App('blt5d4sample2633b').Class('project').Object; var project = Project({ name: 'Super Project #41!' }); project = project.assign({version: 2});
-
decrement(key, number){Object}
object.js, line 184 -
Decreases the number field by a given amount (Note: Decrement is done on the server)
Name Type Description key
String Uid of the number field number
number By how much amount to decrement Throws:
new Error('Not a number');Example
//'blt5d4sample2633b' is a dummy Application API key // Class('class_name').Object returns a Object constructor // 'project' is a uid of a class on Built.io Backend // 'blt12sampleb09157' is uid of an object on Built.io Backend var project = Built.App('blt5d4sample2633b').Class('project').Object(); project = project.decrement('version',2);
-
delete(){Promise.<null>}
object.js, line 1117 -
Deletes the object from Built.io Backend
Throws:
new Error('Uid not found');Example
//'blt5d4sample2633b' is a dummy Application API key // Class('class_name').Object returns a Object constructor // 'project' is a uid of a class on Built.io Backend // 'blt12sampleb09157' is uid of an object on Built.io Backend var project = Built.App('blt5d4sample2633b').Class('project') .Object('blt12sampleb09157'); project.delete() .then(function(){ // console.log('object deleted successfully') });
-
except(fieldUidArray){Object}
object.js, line 895 -
Removes a set of fields from response
Name Type Description fieldUidArray
Array Array of field uid's that need to be excluded from response Example
// 'blt5d4sample2633b' is a dummy Application API key // 'Class('class_name').Object returns a 'Object' constructor // 'project' is a uid of a class on Built.io Backed var obj = Built.App('blt5d4sample2633b').Class('project').Object('blt12sampleb09157'); obj = obj.except(['username']); obj.fetch() .then(function(obj){ // The response won't contain 'username' field console.log(obj.toJSON()) });
-
exceptReference(Reference, fieldUidArray){Object}
object.js, line 917 -
Removes a set of fields from the referenced object
Name Type Description Reference
String field uid fieldUidArray
Array Array of field uids that need to be excluded from the referenced object Example
// 'blt5d4sample2633b' is a dummy Application API key // 'Class('class_name').Object returns a 'Object' constructor // 'project' is a uid of a class on Built.io Backed var obj = Built.App('blt5d4sample2633b').Class('project').Object('blt12sampleb09157'); var obj = obj.include(['bug']) obj = obj.exceptReference('bug',['description']); //description is a reference field that references the bug class obj.fetch() .then(function(obj){ // The response won't contain 'description' field in the Address class object console.log(obj.toJSON()) });
-
fetch(){Promise.<Object>}
object.js, line 1082 -
Fetches the latest version of the object from Built.io Backend
Throws:
new Error('Uid not found');Example
//'blt5d4sample2633b' is a dummy Application API key // Class('class_name').Object returns a Object constructor // 'project' is a uid of a class on Built.io Backend // 'blt12sampleb09157' is uid of an object on Built.io Backend var project = Built.App('blt5d4sample2633b').Class('project') .Object('blt12sampleb09157'); project.fetch() .then(function(project){ // object fetch from Built.io Backend });
-
get(property){variable}
object.js, line 79 -
Gets the data for the given property
Name Type Description property
String The object's property Example
//'blt5d4sample2633b' is a dummy Application API key // Class('class_name').Object returns a Object constructor // 'project' is a uid of a class on Built.io Backend // 'blt12sampleb09157' is uid of an object on Built.io Backend var project = Built.App('blt5d4sample2633b').Class('project').Object({ name:'Super Project #41!', description: 'Small description' }); var value = project.get('name');
-
getACL(){ACL}
object.js, line 571 -
Gets the ACL object from an upload
Example
//'blt5d4sample2633b' is a dummy Application API key // Class('class_name').Object returns a Object constructor // 'project' is a uid of a class on Built.io Backend // 'blt12sampleb09157' is uid of an object on Built.io Backend var project = Built.App('blt5d4sample2633b').Class('project') .Object('blt12sampleb09157'); project.fetch() .then(function(project){ console.log(project.getACL()) })
-
getData(){object}
object.js, line 227 -
Returns the JSON representation of object's data
Example
//'blt5d4sample2633b' is a dummy Application API key // Class('class_name').Object returns a Object constructor // 'project' is a uid of a class on Built.io Backend var project = Built.App('blt5d4sample2633b').Class('project').Object({ name:'Super Project #41!' }); var data = project.getData();
-
getExtensionKey(){String}
object.js, line 1197 -
Gets the extension key for an object
Example
// 'blt5d4sample2633b' is a dummy Application API key var project = Built.App('blt5d4sample2633b').Class('project').Object() project = project.setExtensionKey('bltdb28fsaMplEf1b8'); console.log(project.getExtensionKey());
-
getGroupForKey(fieldUid){Group}
object.js, line 1148 -
Wraps a sub-group in Built.Group construct and returns it
Name Type Description fieldUid
field The uid of the group field Throws:
new Error('Key not found in Object');Example
// 'blt5d4sample2633b' is a dummy Application API key // 'manager' is a group field in Project class. // 'blt12sampleb09157' is uid of a object in 'project' class var project = Built.App('blt5d4sample2633b').Class('project') .Object('blt12sampleb09157') project.fetch() .then(function(project) { var manager = project.getGroupForKey("manager") console.log(manager.toJSON()) })
-
getHeaders(){object}
object.js, line 103 -
Gets the header object
Example
//'blt5d4sample2633b' is a dummy Application API key // Class('class_name').Object returns a Object constructor // 'project' is a uid of a class on Built.io Backend // 'blt12sampleb09157' is uid of an object on Built.io Backend var project = Built.App('blt5d4sample2633b').Class('project').Object(); var headers = project().getHeaders();
-
getLocation(){Location}
object.js, line 376 -
Returns the location of this object
Example
//'blt5d4sample2633b' is a dummy Application API key // Class('class_name').Object returns a Object constructor // 'project' is a uid of a class on Built.io Backend var project = Built.App('blt5d4sample2633b').Class('project').Object(); var location = project.getLocation();
-
getMasterKey(){String}
object.js, line 1244 -
Gets the master key for an object
Example
// 'blt5d4sample2633b' is a dummy Application API key var project = Built.App('blt5d4sample2633b').Class('project').Object() project = project.setMasterKey('bltdb28fsaMplEf1b8'); console.log(project.getMasterKey());
-
getUid(){String}
object.js, line 296 -
Retrieves the uid of the object
Example
//'blt5d4sample2633b' is a dummy Application API key // Class('class_name').Object returns a Object constructor // 'project' is a uid of a class on Built.io Backend // 'blt12sampleb09157' is uid of an object on Built.io Backend var project = Built.App('blt5d4sample2633b').Class('project') .Object('blt12sampleb09157'); var uid = project.getUid();
-
has(key){Boolean}
object.js, line 523 -
Checks whether the object has a given property
Name Type Description key
String The property to be checked Example
//'blt5d4sample2633b' is a dummy Application API key // Class('class_name').Object returns a Object constructor // 'project' is a uid of a class on Built.io Backend // 'blt12sampleb09157' is uid of an object on Built.io Backend var project = Built.App('blt5d4sample2633b').Class('project').Object({ name:'Super Project #41!', version :2 }); var boolean = project.has('name');
-
importFromExcel(){Promise.<notice>}
object.js, line 1570 -
Imports objects from excel file into Built.io Backend
Throws:
new Error("No file found") & new Error('Input file element required for import')Example
'blt5d4sample2633b' is a dummy Application API key Class('class_name').Object returns a Object constructor
On Browser
// Example using input element var appObject = Built.App('blt5d4sample2633b').Object() appObject.importFromExcel(document.getElementById('input_element')) .then(function(result){ // Result object { "notice" : "Excel import process has been initiated. You will receive an email once the process has been completed." } }) //fileObj could be a instance of File or FormData var appObject = Built.App("blt5d4sample2633b").Class('sample').Object(); appObject.importFromExcel(fileObj) .then(function(result) { // Result object { "notice" : "Excel import process has been initiated. You will receive an email once the process has been completed." } });On Node
var appObject = Built.App('blt5d4sample2633b').Object(); appObject.importFromExcel("/home/abc/Pictures/dummy.xlsx") // File path .then(function(result) { // Result object { "notice" : "Excel import process has been initiated. You will receive an email once the process has been completed." } }); var buffer = fs.readFileSync('/home/abc/Pictures/dummy.xlsx'); var appObject = Built.App('blt5d4sample2633b').Object(); appObject.importFromExcel({ bytes : buffer, contentType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', name: 'dummy.xlsx' }) .then(function(result) { // Result object { "notice" : "Excel import process has been initiated. You will receive an email once the process has been completed." } });Common
var appObject = Built.App('blt5d4sample2633b').Object(); appObject.importFromExcel({ base64: "V29ya2luZyBhdCBQYXJzZSBpcyBncmVhdCE", contentType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', //Optional name: 'dummy.xlsx' }); -
include(){Object}
object.js, line 865 -
By default, when a object is fetched referenced object's uids are returned in response. Using this method you can retrieve the reference object itself.
Example
//'blt5d4sample2633b' is a dummy Application API key // Class('class_name').Object returns a Object constructor // 'project' is a uid of a class on Built.io Backend var project = Built.App('blt5d4sample2633b').Class('project').Object(); var project = project.include(['project']); project.fetch() .then(function(project){ console.log(project.toJSON()) })
-
includeOwner(){Object}
object.js, line 849 -
Includes the owner of the object in response
Example
//'blt5d4sample2633b' is a dummy Application API key // Class('class_name').Object returns a Object constructor // 'project' is a uid of a class on Built.io Backend var project = Built.App('blt5d4sample2633b').Class('project').Object(); var project = project.includeOwner();
-
increment(key, number){Object}
object.js, line 205 -
Increases the number field by a given amount (Note: Increment is done on the server)
Name Type Description key
String Uid of number field number
number By how much amount to increment Throws:
new Error('Not a number');Example
//'blt5d4sample2633b' is a dummy Application API key // Class('class_name').Object returns a Object constructor // 'project' is a uid of a class on Built.io Backend // 'blt12sampleb09157' is uid of an object on Built.io Backend var project = Built.App('blt5d4sample2633b').Class('project').Object(); project = project.increment('version',10); //Increases age field value by 10
-
isNew(uid){Boolean}
object.js, line 396 -
Determines whether uid is assigned to this object or not
Name Type Description uid
String Uid of an object Example
//'blt5d4sample2633b' is a dummy Application API key // Class('class_name').Object returns a Object constructor // 'project' is a uid of a class on Built.io Backend // 'blt12sampleb09157' is uid of an object on Built.io Backend var project = Built.App('blt5d4sample2633b').Class('project').Object({ uid:'blt12sampleb09157' }); var boolean = project.isNew();
-
off(event, callback){Object}
realtime.js, line 1710 -
[Only avaliable with realtime plugin]
This function unregisters a single or all event listener(s) from Object instance.Name Type Description event
String The event whose listener needs to be unregistered [Optional] callback
function The callback function used while registering [Optional] Throws:
-
new Error('Callback function to be removed is missing')
-
new Error('Event name is missing');
Example
// 'blt5d4sample2633b' is a dummy Application API key // 'blt111sample2211r' is uid of an object on Built.io Backend var app = Built.App('blt5d4sample2633b').enableRealtime(); var person = app.Class('person').Object('blt111sample2211r'); function cb(data){ console.log(data); } // Sets up a listener for delete event person.on('delete',cb); // Sets up a listener for broadcast event person.on('broadcast',cb); // Specifically removes the delete listener person.off('delete',cb); // Removes all listeners on Person person.off(); // Removes all callbacks attached for delete event on this resource person.off('delete'); // Throws "Event name is missing" person.off(cb)
-
-
on(event, callback){Object}
realtime.js, line 1181 -
[Only avaliable with realtime plugin]
This function registers an event listener on Object instance.Given below is the list of supported events.
- Update
- Delete
- Broadcast
The 'update' event is triggered when the content and/or the ACL of this object is modified. Registered callback is invoked with the updated object.
Delete event is triggered when an object is deleted from Built.io Backend. Registered callback is invoked with the deleted object.
Broadcast event is triggered when a message is broadcasted over this object. Registered callback is invoked with the broadcast message.
Name Type Description event
String The event on which listener should be registered callback
function The callback function to be invoked on event trigger Throws:
new Error("Uid not found");Example
// 'blt5d4sample2633b' is a dummy Application API key // app.Clas('class_name').Object() returns a 'Object' instance var app = Built.App('blt5d4sample2633b').enableRealtime(); var person = app.Class('person').Object('blt5dsamplef62a633b'); person.on('update', function(person) { // updated person object }); person.on('delete', function(person) { // deleted person object }); person.on('broadcast', function(message) { // The message broadcasted on this object });
-
only(Array){Object}
object.js, line 941 -
This method should be used when it is required to only have a set of fields in the base class object's response
Name Type Description Array
Array of field uid's that need to be present in the response Example
// 'blt5d4sample2633b' is a dummy Application API key // 'Class('class_name').Object returns a 'Object' constructor // 'project' is a uid of a class on Built.io Backed // Consider project var obj = Built.App('blt5d4sample2633b').Class('project').Object('blt12sampleb09157'); obj = obj.only(['username']); obj.fetch() .then(function(obj){ // The response will only have the username field console.log(obj.toJSON()) });
-
onlyReference(Reference, Array){Object}
object.js, line 964 -
This method should be used when it is required to only have a set of fields in the referenced object
Name Type Description Reference
String field uid Array
Array of field uids that need to be present in the referenced object Example
// 'blt5d4sample2633b' is a dummy Application API key // 'Class('class_name').Object returns a 'Object' constructor // 'project' is a uid of a class on Built.io Backed // Consider project var obj = Built.App('blt5d4sample2633b').Class('project').Object('blt12sampleb09157'); obj = obj.include(['project']); // 'name' is a reference field that references the Project class obj = obj.onlyReference('project',['name']); obj.fetch() .then(function(obj){ // The response will only have name field in the Project object console.log(obj.toJSON()) });
-
pullValue(key, value){Object}
object.js, line 442 -
For the given field marked multiple, it deletes the first matched value. The method ensures pull operation to be atmoic
Name Type Description key
String Uid of field value
String | Array | Object Values to be deleted Example
//'blt5d4sample2633b' is a dummy Application API key // Class('class_name').Object returns a Object constructor // 'project' is a uid of a class on Built.io Backend // 'blt12sampleb09157' is uid of an object on Built.io Backend var project = Built.App('blt5d4sample2633b').Class('project').Object(); project = project.pullValue('multi_field', { first_name:'first', second_name:'second' });
-
pushValue(key, value){Object}
object.js, line 418 -
Pushes a value in the multiple field. The method ensures push operation to be atmoic
Name Type Description key
String Uid of field value
String | Object | Array Value to be pushed Example
//'blt5d4sample2633b' is a dummy Application API key // Class('class_name').Object returns a Object constructor // 'project' is a uid of a class on Built.io Backend // 'blt12sampleb09157' is uid of an object on Built.io Backend var project = Built.App('blt5d4sample2633b').Class('project').Object(); project = project.pushValue('multi_field', { first_name:'Super Project #41!', second_name:'Super Project #41!' });
-
removeExtensionKey(){Object}
object.js, line 1214 -
Removes the extension key from object
Example
// 'blt5d4sample2633b' is a dummy Application API key var project = Built.App('blt5d4sample2633b').Class('project').Object() project = project.removeExtensionKey();
-
removeHeader(header){Object}
object.js, line 153 -
Removes a header from the object
Name Type Description header
String The header to be removed Example
//'blt5d4sample2633b' is a dummy Application API key // Class('class_name').Object returns a Object constructor // 'project' is a uid of a class on Built.io Backend // 'blt12sampleb09157' is uid of an object on Built.io Backend var project = Built.App('blt5d4sample2633b').Class('project').Object(); var project = project.removeHeader('custom-header');
-
removeMasterKey(){Object}
object.js, line 1261 -
Removes the master key from object
Example
// 'blt5d4sample2633b' is a dummy Application API key var project = Built.App('blt5d4sample2633b').Class('project').Object() project = project.removeMasterKey();
-
save(){Promise.<Object>}
object.js, line 1018 -
Saves/updates the object on Built.io Backend
Example
//'blt5d4sample2633b' is a dummy Application API key // Class('class_name').Object returns a Object constructor // 'project' is a uid of a class on Built.io Backend // 'blt12sampleb09157' is uid of an object on Built.io Backend var Project = Built.App('blt5d4sample2633b').Class('project').Object; var projectWithUid = Project({ uid:'blt12sampleb09157', name:'Super Project #41!' }); // As the object has a uid property set, an update request is sent to Built.io Backend. projectWithUid.save() .then(function(object){ // updated object }); var projectWithoutUid = Project({ name:'Super Project #43!' }); // As the object has no uid property, a create request is sent. projectWithoutUid.save() .then(function(object){ // created object })
-
saveAsDraft(){Promise.<Object>}
object.js, line 991 -
Saves an object as draft, i.e., the object bypasses all validations and is not published
Example
//'blt5d4sample2633b' is a dummy Application API key // Class('class_name').Object returns a Object constructor // 'project' is a uid of a class on Built.io Backend // 'blt12sampleb09157' is uid of an object on Built.io Backend var project = Built.App('blt5d4sample2633b').Class('project').Object(); project.saveAsDraft({ name:'Super Project #41!' }) .then(function(project){ console.log(project.toJSON()); });
-
set(key, value){Object}
object.js, line 270 -
Sets a new key value in object
Name Type Description key
String The key for the new property value
String The value for the new property Example
//'blt5d4sample2633b' is a dummy Application API key // Class('class_name').Object returns a Object constructor // 'project' is a uid of a class on Built.io Backend // 'blt12sampleb09157' is uid of an object on Built.io Backend var project = Built.App('blt5d4sample2633b').Class('project') .Object('blt12sampleb09157'); project = project.set('name','Super Project #41!');
-
setACL(aclObject){Object}
object.js, line 546 -
Sets ACL for this object
Name Type Description aclObject
ACL The ACL object Example
//'blt5d4sample2633b' is a dummy Application API key // Class('class_name').Object returns a Object constructor // 'project' is a uid of a class on Built.io Backend // 'blt12sampleb09157' is uid of an object on Built.io Backend var project = Built.App('blt5d4sample2633b').Class('project').Object(); var acl = Built.ACL(); acl = acl.setPublicDeleteAccess(true); project = project.setACL(acl);
-
setExtensionKey(extensionKey){Object}
object.js, line 1182 -
Sets the extension key for an object
Name Type Description extensionKey
String The Extension key Example
// 'blt5d4sample2633b' is a dummy Application API key var project = Built.App('blt5d4sample2633b').Class('project').Object() project = project.setExtensionKey('bltdb28fsaMplEf1b8');
-
setHeader(header, value){Object}
object.js, line 130 -
Sets a new header
Name Type Description header
String The header key value
String The header value Example
//'blt5d4sample2633b' is a dummy Application API key // Class('class_name').Object returns a Object constructor // 'project' is a uid of a class on Built.io Backend // 'blt12sampleb09157' is uid of an object on Built.io Backend var project = Built.App('blt5d4sample2633b').Class('project').Object(); project = project.setHeader('custom-header','custom-value');
-
setLocation(point){Object}
object.js, line 353 -
Sets a location for this object
Name Type Description point
Location Accepts a instance on Built.Location Example
//'blt5d4sample2633b' is a dummy Application API key // Class('class_name').Object returns a Object constructor // 'project' is a uid of a class on Built.io Backend var location = Buitl.Location(60,80); var project= Built.App('blt5d4sample2633b').Class('project').Object(); project = project.setLocation(location);
-
setMasterKey(masterKey){Object}
object.js, line 1229 -
Sets the master key for an object
Name Type Description masterKey
String The master key Example
// 'blt5d4sample2633b' is a dummy Application API key var project = Built.App('blt5d4sample2633b').Class('project').Object() project = project.setMasterKey('bltdb28fsaMplEf1b8');
-
setReference(field_uid, refValue){Object}
object.js, line 628 -
Assigns referenced object's uids to a reference field of an object
Name Type Description field_uid
String The uid of the field whose references are to be set refValue
String | Array Single uid/SDK object or Array of uids/SDK objects Throws:
new Error('new Error('Uid not found'))Example
//'blt5d4sample2633b' is a dummy Application API key // Class('class_name').Object returns a Object constructor // 'bugs' is a uid of a class on Built.io Backend // 'blt12sampleb09157' is uid of an object on Built.io Backend var app = Built.App('blt5d4sample2633b'); var Bugs = app.Class('bugs').Object; var Project = app.Class('project').Object; var project = Project({ uid:'blt12sampleb09157' }); var bugs = Bugs(); // Using array of SDK objects as argument project = project.setReference('project',[project]); // Using array of uid's as argument project = project.setReference('project',['blt12sampleb0333','blt12sampleb09222']);
-
setReferenceWhere(field_uid, query){Object}
object.js, line 726 -
Fires a query on Built.io Backend and the object that fulfills the query condition is assigned in the reference field. Note: 'query' should be such that only one object should satisfy it, as Built.io Backend doesn't allow multipe references to be set using a 'query'
Name Type Description field_uid
String The uid of the reference field query
object JavaScript object specifying the conditions Example
//'blt5d4sample2633b' is a dummy Application API key // Class('class_name').Object returns a Object constructor // 'bugs' is a uid of a class on Built.io Backend // 'blt12sampleb09111' is uid of an object on Built.io Backend var app = Built.App('blt5d4sample2633b'); var Bugs = app.Class('bugs').Object; var bug = Bugs('blt12sampleb09111'); bug = bug.setReferenceWhere('project', { name: 'Super Project #41!' }); bug.save() .then(function(bug){ console.log(bug.toJSON()) });
-
setReferenceWithObject(field_uid, refObjs){Object}
object.js, line 678 -
This method will first create object(s) in referred class and then assigns its uids in the base class's referring field. Example: Consider you have a reference field 'project' in class 'Bugs' class. This method would first create object(s) in 'Project' class and then assign its 'uids' in 'Bugs' class's reference field 'project'.
Name Type Description field_uid
String The uid of the reference field or "." delimated string for 'group' fields as shown in example refObjs
Object | Array JSON object or an array of plain JavaScript objects or SDK object(s) Example
//'blt5d4sample2633b' is a dummy Application API key // Class('class_name').Object returns a Object constructor // 'bugs' is a uid of a class on Built.io Backend // 'blt12sampleb09111' is uid of an object on Built.io Backend var app = Built.App('blt5d4sample2633b'); var Bugs = app.Class('bugs').Object; var bug = Bugs('blt12sampleb09111'); bug = bug.setReferenceWithObject('project', [{ name: 'Super Project #41!' }]); bug .save() .then(function(bug){ console.log(bug.toJSON()) });
-
setTags(tags){Object}
object.js, line 333 -
Assign tag(s) to this object
Name Type Description tags
Array Array of tags Example
//'blt5d4sample2633b' is a dummy Application API key // Class('class_name').Object returns a Object constructor // 'project' is a uid of a class on Built.io Backend var project = Built.App('blt5d4sample2633b').Class('project').Object(); project = project.setTags(['tag1','tag2']);
-
setUid(uid){Object}
object.js, line 315 -
Assigns a uid
Name Type Description uid
String Uid of an object Example
//'blt5d4sample2633b' is a dummy Application API key // Class('class_name').Object returns a Object constructor // 'project' is a uid of a class on Built.io Backend // 'blt12sampleb09157' is uid of an object on Built.io Backend var project = Built.App('blt5d4sample2633b').Class('project').Object(); project = project.setUid('blt12sampleb09157');
-
timeless(){Object}
object.js, line 802 -
Issues a timeless update, which means that the date of creation and the date of updation are not modified
Example
//'blt5d4sample2633b' is a dummy Application API key // Class('class_name').Object returns a Object constructor // 'project' is a uid of a class on Built.io Backend var project = Built.App('blt5d4sample2633b').Class('project').Object(); project = project.timeless();
-
toBackboneModel(model){Backbone}
object.js, line 1293 -
Returns a Backbone version of the same object
Name Type Description model
Model Takes the Backbone model to be used for conversion. (If no model is specified, Built.io Backend's default model would be used.) Returns:
a BackBone object
Example
//'blt5d4sample2633b' is a dummy Application API key // Class('class_name').Object returns a Object constructor // 'project' is a uid of a class on Built.io Backend // 'blt12sampleb09157' is uid of an object on Built.io Backend var model = Backbone.Model.extend({ getName:function(){ this.get("name"); }, setName:function(name){ this.set("name", name); }, idAttribute:"uid" }); var Project = Built.App('blt5d4924dff62a633b').Class('project').Object; var project = Project({ name:'Super Project #41!' }); var backbone = project.toBackboneModel(model); //Now "backbone" can be used to fetch, save, delete, update object on Built.io Backend. backbone.save(null,{ success:function(res){ // res also has a Backbone model type } }); // Built.io Backend's default Backbone model would be used var backbone = project.toBackboneModel(); //Now "backbone" can be used to fetch, save, delete, update object on Built.io Backend. backbone.save(null,{ success:function(res){ // res also has a Backbone model type } });
-
updateValueAtIndex(key, value, index){Object}
object.js, line 466 -
For the given field marked multiple, it updates the value at the given index. The method ensures update operation to be atmoic
Name Type Description key
String Uid of field value
String | Object Update value for the field based on it type index
number Index at which the value should be updated Throws:
new Error('Index value inappropriate')Example
//'blt5d4sample2633b' is a dummy Application API key // Class('class_name').Object returns a Object constructor // 'project' is a uid of a class on Built.io Backend // 'blt12sampleb09157' is uid of an object on Built.io Backend var project = Built.App('blt5d4sample2633b').Class('project').Object(); project = project.updateValueAtIndex('multi_field', 1);
-
upsert(upsertObject){Object}
object.js, line 489 -
Upserts the object (Updates the matching object if found on Built.io Backend or creates a new object)
Name Type Description upsertObject
object Plain JavaScript object specifying the upsert conditions Example
//'blt5d4sample2633b' is a dummy Application API key // Class('class_name').Object returns a Object constructor // 'project' is a uid of a class on Built.io Backend // 'blt12sampleb09157' if uid of an object on Built.io Backend var Project = Built.App('blt5d4sample2633b').Class('project').Object; var project = Project({ name:'Super Project #41!', version: 1 }); // If object having its name field as 'Super Project #41!' if found, it is updated, // else it creates a new object on Built.io Backend project = project.upsert({ name:'Super Project #41!' }); project.save() .then(function(project){ // do something });
-
upsertForReference(field_uid, upsert){Object}
object.js, line 763 -
Use this method to perfom a upsert(update else insert) operation on reference field.
Name Type Description field_uid
String Reference uid on which UPSERT is to be performed upsert
Built.Upsert Instance of Built.Upsert Example
//'blt5d4sample2633b' is a dummy Application API key // Class('class_name').Object returns a Object constructor // 'bugs' is a uid of a class on Built.io Backend var app = Built.App('blt5d4sample2633b'); var Bugs = app.Class('bugs').Object; var bug = Bugs(); var upsertOps = Built.Upsert([{ condition:{ name:'Super Project #41' }, replacement:{ name: 'Super Project A', description: 'New project' } }]) bug = bug.upsertForReference('project', upsertOps); // The method would first check Project class (the class referred by 'Bugs' class using 'project' field) and // checks if any object with name 'Super Project #41!' exists; if yes, it's name would be replaced by 'Super Project A' and // description by 'New project'. // If not, a new entry would be made with name as 'Super Project A' and description as 'New project' and its // uid would be assigned to reference field 'project.