- Creates all of the objects required by the Model locally
- Requires and sets Utilities, Database, Validation & Sync Libs
- Fetches the associated table info via the Database.describeTableReader() function
- Assigns the Model's columns Array and primary key properties based on information from describeTableReader()
- Auto-assigns foreign keys to the foreignKeys Array if requested
- Instantiates and performs a login check to the SyncAdapter library.
var _init = require("BaseModel"),
Model = new _init.Model(table);
exports.Model = Model;
var _init = require("BaseModel"),
Model = new _init.Model(table);
Model.myCustomFunction = function() {
var newRecord = this.newRecord();
newRecord.dateRightNow = new Date();
return newRecord;
};
exports.Model = Model;
//this wraps: require('/sqlModels/contactModel').Model;
//is a proper JavaScript object
{
id: "123456", firstname: "Boydlee",
lastname: "Pollentine",
gendercode: 1,
fullname: "Boydlee Pollentine",
address1_line1: "5 Rigbys Court",
address1_city: "Norwich",
.......... }
//is JavaScript Array of Objects
[
{ id: "123456", firstname: "Boydlee", lastname: "Pollentine", gendercode: 1,
fullname: "Boydlee Pollentine" .......... },
{ id: "9032190", firstname: "Harry", lastname: "Styles", .... },
{ id: "9032190", firstname: "Barry", lastname: "Johnson", .... },
{ id: "9032190", firstname: "Margeret", lastname: "Braithwaite", .... }
]
//returns a sqlite result set
//use the second optional parameter (BOOLEAN) to objectify the results
//e.g. ContactModel.fetchAllBySqlQuery(_query, true); //objectifies results to JS
//is JavaScript Object that has a set of pre-defined object properties which match
//those of the table in the database
{ id: "123456",
firstname: "",
lastname: "",
gendercode: 1, //will pre-fill if DEFAULT Value exists
fullname: "Boydlee Pollentine"
..........
}
{
id: 1,
name: "Boydlee",
gender: "M"
}