Myna. DataManager

Creates Objects for reading from and writing to database tables

Myna.DataManager is a dynamic Object-Relational Mapping (ORM) tool to simplify basic Create, Read, Update and Delete (CRUD) operations on database tables.

The basic concept is that for a given table Myna.DataManager can generate a manager object that represents that table and knows how to create and delete rows.  That manager can then generate a bean object that represents a specific row in the table that knows how to read and write column values to that row.  Both of these types objects can be extended for extra functionality.

Here is an example

    +- - - - - - - - - - - - - - - - - -+
| table employees |
+- - - - - - - - - - - - - - - - - -+
| emp_id int4 primary key |
| fname varchar |
| mname varchar |
| lname varchar |
| manager_id int4 |
| hire_date date |
+- - - - - - - - - - - - - - - - - -+

var dm = new Myna.DataManager("hr_datasource");

var empManager = dm.getManager("employees");

var newEmpBean = empManager.create({
fname:"Bob",
lname:"Dobb",
hire_date:Date.parse("02/21/1992","m/d/Y")
})

Myna.println (newEmp.get_emp_id()) // Prints the auto generated primary key
newEmp.set_mname("R"); //sets this value in an update

// column values are also available as property proxies on the bean objects:
// see https://developer.mozilla.org/En/Core_JavaScript_1.5_Guide:Creating_New_Objects:Defining_Getters_and_Setters
// for how this works
Myna.println (newEmp.emp_id) // calls get_emp_id() on the bean
newEmp.mname = "R"; // calls set_emp_id("R") on the bean

Tree Organized Tables

The DataManager can also manage MPTT organized tree tables.  This is a method of storing hierarchical data in flat database tables.

For more on this see

Also check out empManager.columns for metadata about each column in the table, such as name, default value, size, type, nullable, precision and more.

Summary
Myna. DataManagerCreates Objects for reading from and writing to database tables
Functions
DataManagerConstructs a Myna.DataManager Object for the supplied datasource
getManagerConstructs a ManagerObject for the supplied table.
getTreeManagerAn extension of getManager that specifically manages Modified Pre-order Tree Traversal (MPTT) organized tables.
managerExistsreturns true if a manager with a given name can be created form this DataManager
Properties
dsDatasource associated with this Myna.DataManager
dbMyna.Database object that represents the database this table resides in
ManagerObjectTable data access object generated and returned by Myna.DataManager.getManager
Functions
addValidatoradds a validation function to this manager’s validation object
addValidatorsadd multiple validators to this manager’s validation object
loadTableDatainternal function to load table data into the manager
removeRemoves or invalidates a row from the managed table matching the supplied primary key
forceDeleteRemoves a row from the managed table matching the supplied primary key
createCreates a record in the database, optionally generating a primary key
queryreturns a Myna.DataSet of information from this table
findreturns an array of primaryKey values that match a search
findBeansreturns a Myna.DataSet of bean objects that match a search
genKeygenerates a primary key value
genLabelgenerates a display label from a column name
getByIdReturns a BeanObject representing the row identified by the supplied primary key
getreturns either an instance of an existing row or the result of getNew
getDefaultreturns the default value for a column name
getDefaultsreturns a structure of all the default values for this table
getLabelreturns the display label for a column name
getMassAssignablereturns an array of the fields that can be assigned via get, getNew, create and BeanObject.setFields
getNewReturns a BeanObject representing a new row not yet inserted
belongsToSets a “belongsTo” relationship with another table.
hasOneSets a “hasOne” relationship with another table.
hasManySets a “hasMany” relationship with another table.
hasBridgeToSets a “many-to-many” relationship with another table.
makeTreeConverts this manager into a TreeManagerObject
setDefaultsets an explicit default value for a column
setDefaultssets several default values at once
setLabelsets an explicit display label for a column
setLabelssets an explicit display label for multiple columns at once
validatorFunctions. uniqueA DataManager-specific validator that validates a value is unique in a column
setMassAssignableSets an array of the fields that can be assigned via get, getNew, create and BeanObject.setFields
afterSavefired after a bean is saved in the database (create or update) but before it is returned
beforeSavefired before a bean is saved (create or update) in the database
afterCreatefired after a bean is created in the database but before it is returned
beforeCreatefired before a bean is created in the database
afterLoadfired after a bean is loaded but before it is returned
beforeLoadfired before a bean is loaded
afterRemovefired after a bean is removed from the database
beforeRemovefired before a bean is removed from the database
afterSaveFieldfired after a bean field is saved to the database
afterSetFieldfired after a bean field is changed, even if not saved to the database
beforeSaveFieldfired before a bean field is saved to the database
beforeSetFieldfired before a bean field is changed, even if not saved to the database
Properties
dmThe Myna.DataManager object that created this manager
dbThe Myna.Database for this manager
deferreddefault, false Sets the deferred status of beans generated by this manager
tableThe Myna.Table for this manager
dsThe datasource name for this manager
columnsThe columns array from Myna.Table.columns for this table
logQueriesif true, log all queries made by this manager default: false
columnNamesThe columnNames array from Myna.Table.columnNames for this table
softDeleteColDate or timestamp column to set to current time instead of deleting rows
validationThis manager’s Myna.Validation instance
TreeManagerObjectTable data access object generated and returned by Myna.DataManager.getTreeManager for Modified Pre-order Tree Traversal (MPTT) organized tables
Functions
createInserts a row in the table relative to an existing node, and re-orders affected nodes.
removeremoves a row in the table and also deletes any descending nodes
hasRootNodereturns true if there is a root node in this table.
getRootNodereturns the root node of this table, or throws an exception
rebuildTreerecalculates left, right, and depth values based on parent ids
BeanObjectRow data access object generated and returned by ManagerObject.getById
Functions
get_<columnName>gets a value for <columnName>
set_<columnName>sets a value for <columnName>
setFieldsSets multiple fields at once
saveFieldPersists a value to its underlying row
forceDeletealias for ManagerObject.forceDelete, which passes this bean’s id
getDatareturns a structure of this bean’s data
getLabelalias for ManagerObject.getLabel
getParentreturn a bean representing this bean’s parent record
getChildrenreturn a Myna.DataSet of beans representing this bean’s child records
removealias for ManagerObject.remove, which passes this bean’s id
saveSaves a deferred bean and returns a Myna.ValidationResult object
validateValidates this bean.
Properties
existstrue if this bean exists in the database
managerThe ManagerObject that created this bean
dmThe Myna.DataManager object that created this bean
isDirtytrue if this bean has unsaved changes, only applies to deferred beans
deferredDefault false determines whether “set” operations update the database
dsThe datasource name for this bean
dataa simple JS object containing this bean’s data
idThe value of the primary key of this bean
columnsThe columns array from Myna.Table.columns for this table
columnNamesThe columnNames array from Myna.Table.columnNames for this table
TreeNodeObjectSub-class of BeanObject generated and returned by <TreeManagerObject.getById>
Functions
moveNodeMoves this node to another location in the tree, only applies to nodes access through <ManagerObject.getTreeManager>
getLeftreturns the value of this node’s “left” property.
getRightreturns the value of this node’s “right” property.
getParentIdreturns the value of this node’s “parent” property.
getParentNodereturns this node’s parent node
isRootNodereturns true if this node is the root node
Properties
childIdsan array of the node ids of this node’s direct children
childNodesan array of the TreeNodes of this node’s direct children
descendantIdsan array of the node ids of all of this node’s descendants
descendantNodesan array of the TreeNodes of all of this node’s descendants
ancestorIdsan array of the node ids of this node’s ancestors
ancestorNodesan array of the TreeNodes of this node’s ancestors

Functions

DataManager

Constructs a Myna.DataManager Object for the supplied datasource

Parameters

dataSourceDatasource Name

getManager

Constructs a ManagerObject for the supplied table.

Parameters

tableNamelowercase name of the table, or singular ProperCased name of table, e.g “part_orders” or “PartOrder”
optionsA JS object representing metadata for this table that can’t be calculated from the table itself See “Options” Below

Options

softDeleteColOptional, default “deleted” If this column exists in the table, then delete operations will instead set this column to the current time.  Find operations will automatically filter rows with this column set
createdColOptional, default “created” If this column exists in the table, then create operations will set this column to the current time.
modifiedColOptional, default “modified” If this column exists in the table, then modify operations will set this column to the current time.  Detail: Creates a ManagerObject for the supplied table.

getTreeManager

An extension of getManager that specifically manages Modified Pre-order Tree Traversal (MPTT) organized tables.

Parameters

tableNameName of MPTT organized table
optionsA JS object representing metadata for the MPTT table.  See “Options” Below

Options

leftCol*Optional, default “lft” * Column name that contains the “left” values
rightCol*Optional, default “rgt” * Column name that contains the “right” values
idCol*Optional, default primary key col * The column that contains the “id” values
parentCol*Optional, default “parent_id” * The column that contains the “parent” values
depthCol*Optional, default null * The column that contains the “depth” values.  If this is null, then this TreeManager will not manage a depth column

See

managerExists

returns true if a manager with a given name can be created form this DataManager

Parameters

nameString.  Table name or model name to check

Properties

ds

Datasource associated with this Myna.DataManager

db

Myna.Database object that represents the database this table resides in

ManagerObject

Table data access object generated and returned by Myna.DataManager.getManager

Summary
Functions
addValidatoradds a validation function to this manager’s validation object
addValidatorsadd multiple validators to this manager’s validation object
loadTableDatainternal function to load table data into the manager
removeRemoves or invalidates a row from the managed table matching the supplied primary key
forceDeleteRemoves a row from the managed table matching the supplied primary key
createCreates a record in the database, optionally generating a primary key
queryreturns a Myna.DataSet of information from this table
findreturns an array of primaryKey values that match a search
findBeansreturns a Myna.DataSet of bean objects that match a search
genKeygenerates a primary key value
genLabelgenerates a display label from a column name
getByIdReturns a BeanObject representing the row identified by the supplied primary key
getreturns either an instance of an existing row or the result of getNew
getDefaultreturns the default value for a column name
getDefaultsreturns a structure of all the default values for this table
getLabelreturns the display label for a column name
getMassAssignablereturns an array of the fields that can be assigned via get, getNew, create and BeanObject.setFields
getNewReturns a BeanObject representing a new row not yet inserted
belongsToSets a “belongsTo” relationship with another table.
hasOneSets a “hasOne” relationship with another table.
hasManySets a “hasMany” relationship with another table.
hasBridgeToSets a “many-to-many” relationship with another table.
makeTreeConverts this manager into a TreeManagerObject
setDefaultsets an explicit default value for a column
setDefaultssets several default values at once
setLabelsets an explicit display label for a column
setLabelssets an explicit display label for multiple columns at once
validatorFunctions. uniqueA DataManager-specific validator that validates a value is unique in a column
setMassAssignableSets an array of the fields that can be assigned via get, getNew, create and BeanObject.setFields
afterSavefired after a bean is saved in the database (create or update) but before it is returned
beforeSavefired before a bean is saved (create or update) in the database
afterCreatefired after a bean is created in the database but before it is returned
beforeCreatefired before a bean is created in the database
afterLoadfired after a bean is loaded but before it is returned
beforeLoadfired before a bean is loaded
afterRemovefired after a bean is removed from the database
beforeRemovefired before a bean is removed from the database
afterSaveFieldfired after a bean field is saved to the database
afterSetFieldfired after a bean field is changed, even if not saved to the database
beforeSaveFieldfired before a bean field is saved to the database
beforeSetFieldfired before a bean field is changed, even if not saved to the database
Properties
dmThe Myna.DataManager object that created this manager
dbThe Myna.Database for this manager
deferreddefault, false Sets the deferred status of beans generated by this manager
tableThe Myna.Table for this manager
dsThe datasource name for this manager
columnsThe columns array from Myna.Table.columns for this table
logQueriesif true, log all queries made by this manager default: false
columnNamesThe columnNames array from Myna.Table.columnNames for this table
softDeleteColDate or timestamp column to set to current time instead of deleting rows
validationThis manager’s Myna.Validation instance

Functions

addValidator

adds a validation function to this manager’s validation object

Parameters

propertyproperty to validate.  If this is set to null, then this validator will be called for every property
validatorEither a String or a validation function.  If this is a string, it must match one of the standard validation functions stored in <Myna.Validation.validatorFunctions>, or the manager-specific validator validatorFunctions.unique This function will be called when needed to validate property See Validator Function below
optionsOptional, default undefined any options needed by the validator

Validator Function

The validator function will be called with a parameters object with these properties

objObject being validated
propertyProperty being validated
labelresult of getLabel for property
valuevalue being validated
optionsvalidator options.  Most validators define their own specific options, but all validators accept the options below

Validator Options

whenA function that will take the same parameters as a validator function and return true if the validator should be run.  This is normally used conditionally validate one of the built-in validators

Returns

this validation instance

Examples

manager.addValidator("first_name","length",{
min:3,
max:25
})

//only validate spouse_name when married is true
manager.addValidator("spouse_name","required",{
when:function(params){
return params.obj.married
}
})

function isBob(params){
var vr = new Myna.ValidationResult();
if (params.value != "Bob"){
var msg = params.options.message || params.label + " is not Bob!"
vr.addError(msg,colname)
}
return vr;
}

manager.addValidator("first_name",isBob,{
message:"Inferior name entered."
})

See

addValidators

add multiple validators to this manager’s validation object

Parameters

validator_configJS Object keyed by property name, with sub-objects keyed by validator name (or “custom” for custom validators), with values equal to validator options (or {}, if no options)

Returns

this validation instance

Example

manager.addValidators({
name:{
required:{},
type:"string",
regex:{
pattern:/^[A-Za-z ]+$/,
message:"Names must only contain Letters and spaces"
},

},
dob:{
type:"date",
value:{
min:new Date().add(Date.YEAR,-150),
max:new Date()
}
},
children:{
type:"array",
length:{
max:12
},
custom:function(params){
var vr = new Myna.ValidationResult();
params.value.forEach(function(child,index){
vr.merge(this.validate(child),"child_" + index "_")
})

return vr;
}
}
})

See

loadTableData

internal function to load table data into the manager

remove

Removes or invalidates a row from the managed table matching the supplied primary key

Parameters

idprimary key value of the row to remove

Detail

This function checks for the existence of softDeleteCol and will update it to the current time if available.  If no softDeleteCol is defined, then forceDelete is called to remove the row form the table.

forceDelete

Removes a row from the managed table matching the supplied primary key

Parameters

idprimary key value of the row to remove

Detail

If this manager hasOne or hasMany related managers with cascading deletes, these related rows will be deleted regardless of the existence of softDeleteCol in the related managers

create

Creates a record in the database, optionally generating a primary key

Parameters

requiredFieldsAn object where the keys are column names and the values are the values to insert.
allowMassAssignOptional, default false If set to true, then even fields that are not set as mass assignable will be set

Detail

requiredFields must contain entries for all non-null columns without default values, except the primary key.  If the primary key is not specified, and the column does not have a default value, genKey is called to generate a key.  Any extra columns supplied will be inserted as well.

Returns

instance of the Bean that represents the new row.  See getById

Example

         +- - - - - - - - - - - - - - - - - -+
| table employees |
+- - - - - - - - - - - - - - - - - -+
| emp_id int4 primary key |
| fname varchar |
| mname varchar |
| lname varchar |
| manager_id int4 |
| hire_date date |
+- - - - - - - - - - - - - - - - - -+

var dm = new Myna.DataManager("hr_datasource");

var empManager = dm.getManager("employees");

var newEmpBean = empManager.create({
fname:"Bob",
lname:"Dobb",
hire_date:Date.parse("02/21/1992","m/d/Y")
})

query

returns a Myna.DataSet of information from this table

Parameters

patternif this is a String, Number, or Date, the primary key will be searched for this value.  If this is an object, each key is expected to by a column name and the value a pattern to search for.  In either mode, the SQL wildcard (%) can be used for a “like” search.  Special pattern properties are available for advanced queries.  See Special Pattern Properties below
optionsquery options, see options below

Special Pattern Properties

select*default, “ This is the select expression to use for this query.  Any valid SQL will work
wheredefault, false This pattern property works much like the sql property of Myna.Query.  Any valid SQL can be used here, and parameter placeholders can be used just as in Myna.Query.  Parameters are replaced from the other properties of pattern.  See example below
orderBydefault, false if defined, this is a valid SQL order by expression
”colname operation”default, false if defined, will perform operation against colname with the value of this property. e.g : “age <”:12

Options

caseSensitivedefault false if true, patterns will be matched in a case-sensitive manner
includeSoftDeleteddefault false if true, soft deleted columns will be included in query results
[queryOptions]Any other Myna.Query options such as maxRows

Note

The Myna.DataSet returned has an extra property, “totalRows” that contains the number of items that would be returned if the query was not constrained.  This is useful if page, or startRow are passed as options

Examples

var employees = new Myna.DataManager("some_ds").getManager("employees");

//Find all employees of a given supervisor
var grunts = man.query({
supervisor_id:"0102236",
"inactive is not":null
})


//more complicated search with wildcards
var assitants = employees.find({
supervisor_id:"0102236"
job_title:"%assistant%"
})

// an even more complicated search with "select",
// "where" and "orderBy" pattern properties
// and including soft deleted records
var bobs_helpers = employees.find({
select:"name",
where:<ejs>
supervisor_id = {supervisor_id}
and (
job_title like {job_title}
or start_date > {start_date:date}
)
</ejs>,
orderBy:"name desc",

supervisor_id:"55652315",
job_title:"%assitant%",
start_date:new Date().add(Date.year,-1)
},{
includeSoftDeleted:true
})

See

<queryCol> <queryValue> find findBeans

find

returns an array of primaryKey values that match a search

Parameters

patternif this is a String, Number, or Date, the primary key will be searched for this value.  If this is an object, each key is expected to by a column name and the value a pattern to search for.  In either mode, the SQL wildcard (%) can be used for a “like” search.  A special property where can be used for complex where clauses, see ”where” pattern property below
optionsOptional, default false options to pass to the underlying ManagerObject.query call

”where” pattern property

This pattern property works much like the sql property of Myna.Query.  Any valid SQL that makes sense in a where clause can be used here, and parameter placeholders can be used just as in Myna.Query.  Parameters are replaced from the other properties of pattern.  See example below

Examples

var employees = new Myna.DataManager("some_ds").getManager("employees");

// a primary key search
var bob_exists = employees.find("55652315").length

//one column search for exact match
var bobs_emps = employees.find({
manager_id:"55652315"
})

//Who are Bob's employees?
bobs_emps.forEach(function(employee_id){
Myna.print(employees.getById(employee_id).get_name() +"<br>");
})

//more complicated search with wildcards
var bobs_helpers = employees.find({
manager_id:"55652315",
job_title:"%assitant%"
})

//an even more complicated search with where property
var bobs_helpers = employees.find({
where:<ejs>
manager_id = {manager_id}
and (
job_title like {job_title}
or start_date > {start_date:date}
)
</ejs>,
manager_id:"55652315",
job_title:"%assitant%",
start_date:new Date().add(Date.year,-1)
})

//include deleted "helpers"
var bobs_helpers = employees.find({
manager_id:"55652315",
job_title:"%assitant%",
},{
includeSoftDeleted:true
})

See

findBeans

findBeans

returns a Myna.DataSet of bean objects that match a search

Parameters

patternif this is a string, the primary key will be searched for this value.  If this is an object, each key is expected to by a column name and the value a pattern to search for.  In either mode, the SQL wildcard (%) can be used for a “like” search.
optionsOptional, default false options to pass to the underlying ManagerObject.query call

Note

The Myna.DataSet returned has an extra property, “totalRows” that contains the number of items that would be returned if the query was not constrained.  This is useful if page, or startRow are passed as options

Examples

var employees = new Myna.DataManager("some_ds").getManager("employees");

// a primary key search
var bob_exists = employees.find("55652315").length

//one column search for exact match
var bobs_emps = employees.findBeans({
manager_id:"55652315"
})

//Who are Bob's employees?
bobs_emps.forEach(function(employee){
Myna.print(employee.get_name() +"<br>");
})
//What are their email addresses?
Myna.printDump(bobs_emps.valueArray("email"),"Bob's Emloyees' Email")


//more complicated search with wildcards
var bobs_helpers = employees.findBeans({
manager_id:"55652315",
job_title:"%assitant%"
})

//Using aggregate math: Bob's employees average salary
//See Myna.DataSet
var bobs_emps_avg_sal = employees.findBeans({
manager_id:"55652315"
}).average("salary")

See

find

genKey

generates a primary key value

Detail

By default this function checks the type of the primary key and returns Myna.createUuid for text keys or returns the maximum value of the primary key column + 1 for numeric keys.  This is not the ideal algorithm and should be replaced with a database specific means of generating a primary key.

(end)

genLabel

generates a display label from a column name

The default implementation either uses one of the special replacements below, or replaces all underbars with spaces and calls String.titleCap on the result.  You can override this function in your models for custom behavior

Special Replacements

idID

getById

Returns a BeanObject representing the row identified by the supplied primary key

Parameters

idprimary key value of the row to retrieve

Detail

This function loads the data from the indicated row into into a <Myna.DataManager.prototype.BeanBase> object.  Each bean is generated with get_<column name> and set_<column name> functions.  The set functions will immediately set the value in the underlying row.

If a an object with the specified id cannot be found, an exception is thrown

See

get

returns either an instance of an existing row or the result of getNew

Parameters

valuesOptionsal, default null JS object containing the values for this object

Detail

This function attempts to create a usable bean even if there is no matching record.  If values is provided with a valid primary key, then getById is called, BeanObject.deferred is set to true, and BeanObject.setFields is called with values.  Otherwise getNew is called with values.  Regardless, the resulting bean will be deferred and BeanObject.save must be called to persist changes

Note

Any defaults set by setDefault will be applied before returning the bean object

Example

//crate or update an order from form data:
var order = new Myna.DataManager(ds).getManager("orders").get($req.rawData)
var result = order.save();
if (result.success) {
...
} else{
...
}

getDefault

returns the default value for a column name

Parameters

colnamelowercase name of column to retrieve a default value for

If an explicit default for this column has been set via setDefault, or setDefaults, that is returned.  Otherwise, null is returned

See Also

getDefaults

getDefaults

returns a structure of all the default values for this table

See

getDefault

getLabel

returns the display label for a column name

Parameters

colnamelowercase name of column to retrieve a label for

If an explicit label for this column has been set via setLabel, that is returned.  Otherwise, the result of genLabel is returned

getMassAssignable

returns an array of the fields that can be assigned via get, getNew, create and BeanObject.setFields

See

getNew

Returns a BeanObject representing a new row not yet inserted

Parameters

initialValuesobject representing the initial values of this object.  If this does not include a value for the primary key, the primary key will be set to the result from genKey.

Note

Any defaults set by setDefault will be applied before returning the bean object

See

belongsTo

Sets a “belongsTo” relationship with another table.

This function has 3 parameter patterns

Model Name

nameName of model to associate, or a table name.  Model names are the ProperCased singular of the table name
//these are equivalent
var Person = dm.getManager("Person")
Person.belongsTo("Profile")
Person.belongsTo("profiles")

Model Definition object

nameName of model or table to associate
aliasOptional, default _name_ Name to use when attaching related beans.  Using different alias allows you to model multiple belongsTo relationships to the same table
conditionsOptional, default null “where” pattern Object to contain this association, see ManagerObject.find.  You do NOT need this to constrain by the foreign key
foreignKey*Optional, foreign table’s primary key * Name of column in related table that this table refers to.  This is almost always the primary key of that table
localKey*Optional, default alias +”_id” * The column in this table that contains the foreign key value.  This defaults to the underbar(_) separated alias of the associated model +”_id”
cascadeOptional, default false This affects the treatment of the related model when a record is deleted from this model.  A value of false, undefined or null will do nothing.  The string “null” will set null values for the foreignKey column in the related table.  The string “delete” will delete the related record in the related table
this.belongsTo({
name:"Profile",
conditions:{
where:"public = 1 and modified > {oneYearAgo:date}",
oneYearAgo:new Date().add(Date.YEAR,-1).clearTime()
}
})

Model definition object array

this.belongsTo([{
name:"Profile",
conditions:{
where:"public = 1 and modified > {oneYearAgo:date}",
oneYearAgo:new Date().add(Date.YEAR,-1).clearTime()
}]
},{
name:"Employee"
}])

Detail

This maps a one-to-one relationship with the related table to this one.  Once set, any beans returned by this manager will include a function with the same name as the related model that represents the result of <relatedModel>.get() for the related row in the related table.  This is best shown by example

// --- from a FlightPath MVC app ---
//Person Model
function init(){
this.belongsTo("Profile")
}
//Person controller
function edit(params){
this.set("person",this.Person.get({id:params.id}));
}
//person_edit view
Name: <input name="name" value:"<%=person.name%>"><br>
<!--
this is the same as
$FP.getModel("Profile").findBeans({person_id:person.id}).first().email
-->
Email: <input name="Profile.email" value:"<%=person.Profile().email%>"><br>

Note that calling Profile() in the above code will cause the “parent” bean to be created if it doesn’t exist and set this bean to BeanObject.deferred.  When this bean is saved the parent bean will be inserted, if any changes have been made.  To avoid this (and intentionally create an orphan bean) set the related column to an explicit null value, or just don’t make any changes to the returned “parent” bean

hasOne

Sets a “hasOne” relationship with another table.

This function has 3 parameter patterns

Model Name

nameName of model to associate, or a table name.  Model names are the ProperCased singular of the table name
//these are equivalent
var Person = dm.getManager("Person")
Person.hasOne("Profile")
Person.hasOne("profiles")

Model Definition object

nameName of model or table to associate
aliasOptional, default _name_ Name to use when attaching related beans.  Using different alias allows you to model multiple hasOne relationships to the same table
conditionsOptional, default null “where” pattern Object to contain this association, see ManagerObject.find.  You do NOT need this to constrain by the foreign key
foreignKey*Optional, default modelname +”_id” * name of column in related model that refers to this model
localKey*Optional, default model’s primary key * This is the column in this table that contains the foreign key value.  This is almost always the primary key of this table
cascadeOptional, default false This affects the treatment of the related model when a record is deleted from this model.  A value of false, undefined or null will do nothing.  The string “null” will set null values for the foreignKey column in the related table.  The string “delete” will delete the related record in the related table
var Person = dm.getManager("Person")
Person.hasOne({
name:"Profile",
alias:"RecentPublicProfile",
conditions:{
where:"public = 1 and modified > {oneYearAgo:date}",
oneYearAgo:new Date().add(Date.YEAR,-1).clearTime()
}
})

Model definition object array

var Person = dm.getManager("Person")
Person.hasOne([{
name:"Profile",
alias:"RecentPublicProfile",
conditions:{
where:"public = 1 and modified > {oneYearAgo:date}",
oneYearAgo:new Date().add(Date.YEAR,-1).clearTime()
}]
},{
name:"Profile"
}])

Detail

This maps a one-to-one relationship with the related table to this one.  Once set, any beans returned by this manager will include a property with the same name as the related model that represents the result of <relatedModel>.get() for the related row in the related table.  This is best shown by example

// --- from a FlightPath MVC app ---
//Person Model (a DataManager.ManagerObject)
function init(){
this.hasOne("Profile")
}
//Person controller
function edit(params){
this.set("person",this.Person.get({id:params.id}));
}
//person_edit view
Name: <input name="name" value:"<%=person.name%>"><br>
<!--
this is the same as
$FP.getModel("Profile").findBeans({person_id:person.id}).first().email
-->
Email: <input name="Profile.email" value:"<%=person.Profile().email%>"><br>

Note that calling Profile() in the above code will cause the bean to be created if it doesn’t exist and set this bean to BeanObject.deferred.  If any changes are made to the related bean, it will be inserted when this bean is saved.  To force an empty related bean to save, set BeanObject.isDirty to true for the related bean

hasMany

Sets a “hasMany” relationship with another table.

This function has 3 parameter patterns

Model Name

namePlural name of model or exact table name to associate.  Plural Model names are the ProperCased table name, e.g profiles becomes Profiles, and user_profiles would be UserProfiles
//these are equivalent
var Person = dm.getManager("Person")
Person.hasMany("Posts")
Person.hasMany("posts")

Model Definition object

namePlural name of model exact table name to associate.
aliasOptional, default _name_ Name to use when attaching related beans.  Using different alias allows you to model multiple hasMany relationships to the same table
conditionsOptional, default null “where” pattern Object to contain this association, see ManagerObject.find.  You do NOT need this to constrain by the foreign key
foreignKey*Optional, default modelname +”_id” * name of column in related model that refers to this model
localKey*Optional, default model’s primary key * This is the column in this table that contains the foreign key value.  This is almost always the primary key of this table
orderByOptional, default null Valid SQL order by expression. if defined, this will be used to order the related beans.
cascadeOptional, default false This affects the treatment of the related model when a record is deleted from this model.  A value of false, undefined or null will do nothing.  The string “null” will set null values for the foreignKey column in the related table.  The string “delete” will delete the related record in the related table
var Person = dm.getManager("Person")
Person.hasMany({
name:"Posts",
alias:"RecentPosts",
conditions:{
where:"published = 1 and modified > {oneYearAgo:date}",
oneYearAgo:new Date().add(Date.YEAR,-1).clearTime()
},
orderBy:"category_title ASC, date_published DESC"
})

Model definition object array

var Person = dm.getManager("Person")
Person.hasMany([{
name:"Posts",
alias:"RecentPosts",
conditions:{
where:"published = 1 and modified > {oneYearAgo:date}",
oneYearAgo:new Date().add(Date.YEAR,-1).clearTime()
},
orderBy:"category_title ASC, date_published DESC"
},{
name:"Posts",
orderBy:"category_title ASC, date_published DESC"
},{
name:"Favorites"
}])

Detail

This maps a one-to-many relationship with the related table to this one.  Once set, any beans returned by this manager will include a function with the same name as the related alias that represents the result of <relatedModel>.findBeans(), constrained by the foreign key relationship.  This is best shown by example

// --- from a FlightPath MVC app ---
//Person Model
function init(){
this.hasMany("Posts")
}
//Person controller
function edit(params){
this.set("person",this.Person.get({id:params.id}));
}
//person_edit view
Name: <input name="name" value:"<%=person.name%>"><br>
<!--
person.Posts is the same as
$FP.getModel("Post").findBeans({person_id:person.person_id})
-->
Posts:
<ul>
<@loop array="person.Posts()" element="post" index="i">
<li> <%=post.title%>
</@loop>
</ul>

Note that the DataSet result from Posts() above will also contain a getNew() function that is an alias for the related Manager’s getNew() function.  Calling this will create a new instance of the related bean and add it to this object’s relatedBean array.  The related column will be set to this bean’s localKey value

hasBridgeTo

Sets a “many-to-many” relationship with another table.

This function has 3 parameter patterns

Model Name

namePlural name of model or exact table name to associate.  Plural Model names are the ProperCased table name, e.g profiles becomes Profiles, and user_profiles would be UserProfiles
//these are equivalent
var Person = dm.getManager("Person")
Person.hasBridgeTo("Tags")
Person.hasBridgeTo("tags")

Model Definition object

namePlural name of model exact table name to associate.
aliasOptional, default _name_ Name to use when attaching related beans.  Using different alias allows you to model multiple hasMany relationships to the same table
conditionsOptional, default null “where” pattern Object to contain this association, see ManagerObject.find.  You do NOT need this to constrain by the foreign key
bridgeTableOptional, default [relatedModel.tableName,thisModel.tableName].sort().join(“_”) name of bridge table.  Defaults to the two tables names in alphabetical order, separated by underbars(_)
localBridgeKeyOptional, default primary key the field in the bridge table that stores this table’s ids
foreignBridgeKeyOptional, default foreign table primary key the field in the bridge table that stores the foreign table’s ids
foreignKey*Optional, default modelname +”_id” * name of column in related model that refers to this model
localKey*Optional, default model’s primary key * This is the column in this table that contains the foreign key value.  This is almost always the primary key of this table
orderByOptional, default null Valid SQL order by expression. if defined, this will be used to order the related beans.
cascadeOptional, default false This affects the treatment of the related model when a record is deleted from this model.  A value of false, undefined or null will do nothing.  The string “null” will set null values for the foreignKey column in the related table.  The string “delete” will delete the related record in the related table
var Person = dm.getManager("Person")
Person.hasBridgeTo({
name:"Tags",
alias:"RecentTags",
conditions:{
where:"published = 1 and modified > {oneYearAgo:date}",
oneYearAgo:new Date().add(Date.YEAR,-1).clearTime()
},
orderBy:"category_title ASC, date_published DESC"
})

Model definition object array

var Person = dm.getManager("Person")
Person.hasBridgeTo([{
name:"Tags",
alias:"RecentTags",
conditions:{
where:"published = 1 and modified > {oneYearAgo:date}",
oneYearAgo:new Date().add(Date.YEAR,-1).clearTime()
},
orderBy:"category_title ASC, date_published DESC"
},{
name:"Tags",
orderBy:"category_title ASC, date_published DESC"
}])

Detail

This maps a many-to-many relationship with the related table to this one.  This requires a “bridge” table i.e a table that maps the primary keys of both tables.  Once defined, any beans returned by this manager will include a function with the same name as the related alias that represents the result of <relatedModel>.findBeans(), constrained by the foreign key relationship.  This is best shown by example

// --- from a FlightPath MVC app ---
//Person Model
function init(){
this.hasMany("Tags")
}
//Person controller
function edit(params){
this.set("person",this.Person.get({id:params.id}));
}
//person_edit view
Name: <input name="name" value:"<%=person.name%>"><br>
<!--
person.Posts is the same as
$FP.getModel("Post").findBeans({person_id:person.person_id})
-->
Posts:
<ul>
<@loop array="person.Tags()" element="tag" index="i">
<li> <%=tag.title%>
</@loop>
</ul>

Note that the DataSet result from Tags() above will also contain a getNew() function.  Calling this will create a new instance of the related bean and add it to this object’s relatedBean array.  The related column will be set to this bean’s localKey value

makeTree

Converts this manager into a TreeManagerObject

Parameters

optionsTreeManagerObject options

See

setDefault

sets an explicit default value for a column

Parameters

colnamecolumn name to set a default value for
defaultValueDefault value to set.  If this is a function, it will be executed and its return value will be used.  This function will be called with the column name, and a reference to this manager

Note

Defaults are automatically applied by getNew and get to the resulting deferred bean.  Direct calls to findBeans, getById and create will not apply defaults.

See Also

setDefaults

sets several default values at once

Parameters

mapJS object where the keys are column names and the values are default values

See

setLabel

sets an explicit display label for a column

Parameters

colnamecolumn name to map
labellabel so set

setLabels

sets an explicit display label for multiple columns at once

Parameters

mapJS object where the keys are column names and the values are labels

validatorFunctions. unique

A DataManager-specific validator that validates a value is unique in a column

Parameters

caseSensitiveOptional, default false Set to true for exact matches.  Only applies to character columns
includeSoftDeletedOptional, default false set to true to include soft deleted rows in the search.

Detail

This will perform a query against the current table looking for any instances of this value, NOT associated with this primary key.  If any are found this validator will add an error .

See

setMassAssignable

Sets an array of the fields that can be assigned via get, getNew, create and BeanObject.setFields

Parameters

fieldNamesArray of filed names allowed to be mass assigned

Detail

By default, all fields ins a BeanObject can be assigned via get, getNew, create and BeanObject.setFields.  This can be a problem for fields like “admin”.  You don’t want such fields to be set by manipulating the url.  To prevent this, use this function to set what fields can be set in the mass assignment functions.  All other fields must be set via BeanObject.saveField or any of the set_fieldname functions

See

afterSave

fired after a bean is saved in the database (create or update) but before it is returned

Parameters

beanthe newly saved bean

Returns

undefined

//override
man.afterSave = function (bean) {
var user = $cookie.getAuthUser();
myna.log("audit","User {first_name} {last_name} saved object".format(user));
}

//merge
man.after("afterSave",function (bean) {
var user = $cookie.getAuthUser();
myna.log("audit","User {first_name} {last_name} saved object".format(user));
})

beforeSave

fired before a bean is saved (create or update) in the database

Parameters

datathe data to save

Returns

undefined

//override
man.beforeSave = function (data) {
var user = $cookie.getAuthUser();
myna.log("audit","User {first_name} {last_name} saved object".format(user));
}

//merge
man.before("beforeSave",function (data) {
var user = $cookie.getAuthUser();
myna.log("audit","User {first_name} {last_name} saved object".format(user));
})

afterCreate

fired after a bean is created in the database but before it is returned

Parameters

beanthe newly created bean

Returns

undefined

//override
man.afterCreate = function (bean) {
var user = $cookie.getAuthUser();
myna.log("audit","User {first_name} {last_name} created object".format(user));
}

//merge
man.after("afterCreate",function (bean) {
var user = $cookie.getAuthUser();
myna.log("audit","User {first_name} {last_name} created object".format(user));
})

beforeCreate

fired before a bean is created in the database

Parameters

datathe data to create

Returns

undefined

//override
man.beforeCreate = function (data) {
var user = $cookie.getAuthUser();
myna.log("audit","User {first_name} {last_name} created object".format(user));
}

//merge
man.before("beforeCreate",function (data) {
var user = $cookie.getAuthUser();
myna.log("audit","User {first_name} {last_name} created object".format(user));
})

afterLoad

fired after a bean is loaded but before it is returned

Parameters

beanthe newly loaded bean

Returns

undefined

//override
man.afterLoad = function (bean) {
var user = $cookie.getAuthUser();
myna.log("audit","User {first_name} {last_name} loaded object".format(user));
}

//merge
man.after("afterLoad",function (bean) {
var user = $cookie.getAuthUser();
myna.log("audit","User {first_name} {last_name} loaded object".format(user));
})

beforeLoad

fired before a bean is loaded

Parameters

datathe newly loaded bean

Returns

undefined

//override
man.beforeLoad = function (data) {
var user = $cookie.getAuthUser();
myna.log("audit","User {first_name} {last_name} loaded object".format(user));
}

//merge
man.before("beforeLoad",function (data) {
var user = $cookie.getAuthUser();
myna.log("audit","User {first_name} {last_name} loaded object".format(user));
})

afterRemove

fired after a bean is removed from the database

Parameters

idid of removed bean

Returns

undefined

//override
man.afterRemove = function (bean) {
var user = $cookie.getAuthUser();
myna.log("audit","User {first_name} {last_name} removed object".format(user));
}

//merge
man.after("afterRemove",function (bean) {
var user = $cookie.getAuthUser();
myna.log("audit","User {first_name} {last_name} removed object".format(user));
})

beforeRemove

fired before a bean is removed from the database

Parameters

idid of removed bean

Returns

undefined

//override
man.beforeRemove = function (id) {
var user = $cookie.getAuthUser();
myna.log("audit","User {first_name} {last_name} removed object".format(user));
}

//merge
man.before("beforeRemove",function (id) {
var user = $cookie.getAuthUser();
myna.log("audit","User {first_name} {last_name} removed object".format(user));
})

afterSaveField

fired after a bean field is saved to the database

Parameters

beanbean being modified
fieldNamename of field being modified
newValuenew value
oldValueoriginal value

Returns

undefined

//override
man.afterSaveField = function (bean,fieldName,newValue,oldValue) {
var user = $cookie.getAuthUser();
myna.log("audit","User {first_name} {last_name} modified object".format(user));
}

//merge
man.after("afterSaveField",function (bean,fieldName,newValue,oldValue) {
var user = $cookie.getAuthUser();
myna.log("audit","User {first_name} {last_name} modified object".format(user));
})

afterSetField

fired after a bean field is changed, even if not saved to the database

Parameters

beanbean being modified
fieldNamename of field being modified
newValuenew value
oldValueoriginal value

Returns

undefined

//override
man.afterSetField = function (bean,fieldName,newValue,oldValue) {
var user = $cookie.getAuthUser();
myna.log("audit","User {first_name} {last_name} modified object".format(user));
}

//merge
man.after("afterSetField",function (bean,fieldName,newValue,oldValue) {
var user = $cookie.getAuthUser();
myna.log("audit","User {first_name} {last_name} modified object".format(user));
})

beforeSaveField

fired before a bean field is saved to the database

Parameters

beanbean being modified
fieldNamename of field being modified
newValuenew value
oldValueoriginal value

Returns

undefined

//override
man.beforeSaveField = function (bean,fieldName,newValue,oldValue) {
var user = $cookie.getAuthUser();
myna.log("audit","User {first_name} {last_name} modified object".format(user));
}

//merge
man.before("beforeSaveField",function (bean,fieldName,newValue,oldValue) {
var user = $cookie.getAuthUser();
myna.log("audit","User {first_name} {last_name} modified object".format(user));
})

beforeSetField

fired before a bean field is changed, even if not saved to the database

Parameters

beanbean being modified
fieldNamename of field being modified
newValuenew value
oldValueoriginal value

Returns

undefined

//override
man.beforeSetField = function (bean,fieldName,newValue,oldValue) {
var user = $cookie.getAuthUser();
myna.log("audit","User {first_name} {last_name} modified object".format(user));
}

//merge
man.before("beforeSetField",function (bean,fieldName,newValue,oldValue) {
var user = $cookie.getAuthUser();
myna.log("audit","User {first_name} {last_name} modified object".format(user));
})

Properties

dm

The Myna.DataManager object that created this manager

db

The Myna.Database for this manager

deferred

default, false Sets the deferred status of beans generated by this manager

See: BeanObject.deferred

table

The Myna.Table for this manager

ds

The datasource name for this manager

columns

The columns array from Myna.Table.columns for this table

logQueries

if true, log all queries made by this manager default: false

columnNames

The columnNames array from Myna.Table.columnNames for this table

softDeleteCol

Date or timestamp column to set to current time instead of deleting rows

Detail

If this column exists in the table, then remove operations will instead set this column to the current time.  Find operations will automatically filter rows where this column is non-null, unless the includeSoftDeleted option is passed

See

validation

This manager’s Myna.Validation instance

This Myna.Validation instance is used to validate beans created by this manager.

See

TreeManagerObject

Table data access object generated and returned by Myna.DataManager.getTreeManager for Modified Pre-order Tree Traversal (MPTT) organized tables

This object contains all of the functions of ManagerObject plus MPTT specific functions.

See Also

Summary
Functions
createInserts a row in the table relative to an existing node, and re-orders affected nodes.
removeremoves a row in the table and also deletes any descending nodes
hasRootNodereturns true if there is a root node in this table.
getRootNodereturns the root node of this table, or throws an exception
rebuildTreerecalculates left, right, and depth values based on parent ids

Functions

create

Inserts a row in the table relative to an existing node, and re-orders affected nodes.

Parameters

dataJS Object containing the non MPTT data
locationOptional JS object defining where to insert this node.  See “Location” below

Location

underNodeOptional, default null The id of the parent node to insert under.  This is unused if beforeNode is defined.  Will append as the last child of underNode
beforeNodeOptional, default null The id of the node before which this node should be inserted

Note

If both underNode and beforeNode are null, then this node will be inserted as the root node, if the table is empty, or as the last child of the root node.  This function calls ManagerObject.create.

See

remove

removes a row in the table and also deletes any descending nodes

Parameters

idprimary key value of node to delete

Note

When removing the root node of the tree the entire tree will be deleted

See

hasRootNode

returns true if there is a root node in this table.

getRootNode

returns the root node of this table, or throws an exception

rebuildTree

recalculates left, right, and depth values based on parent ids

If an MPTT organized table has correct parent ids defined but inaccurate or missing right, left and depth values, this function will rebuild them.  This is useful for converting an existing table to an MPTT organized table, or if an non-MPTT aware process modifies the table.

Note

This is a recursive function and may run out of memory for very large trees

BeanObject

Row data access object generated and returned by ManagerObject.getById

Summary
Functions
get_<columnName>gets a value for <columnName>
set_<columnName>sets a value for <columnName>
setFieldsSets multiple fields at once
saveFieldPersists a value to its underlying row
forceDeletealias for ManagerObject.forceDelete, which passes this bean’s id
getDatareturns a structure of this bean’s data
getLabelalias for ManagerObject.getLabel
getParentreturn a bean representing this bean’s parent record
getChildrenreturn a Myna.DataSet of beans representing this bean’s child records
removealias for ManagerObject.remove, which passes this bean’s id
saveSaves a deferred bean and returns a Myna.ValidationResult object
validateValidates this bean.
Properties
existstrue if this bean exists in the database
managerThe ManagerObject that created this bean
dmThe Myna.DataManager object that created this bean
isDirtytrue if this bean has unsaved changes, only applies to deferred beans
deferredDefault false determines whether “set” operations update the database
dsThe datasource name for this bean
dataa simple JS object containing this bean’s data
idThe value of the primary key of this bean
columnsThe columns array from Myna.Table.columns for this table
columnNamesThe columnNames array from Myna.Table.columnNames for this table

Functions

get_<columnName>

gets a value for <columnName>

Detail

This function is generated for every column in the associated table.

set_<columnName>

sets a value for <columnName>

Parameters

newvalnew value for the column

Returns

Myna.ValidationResult object representing the result of the set.

Detail

This function is generated for every column in the associated table, except for the primary key.

setFields

Sets multiple fields at once

Parameters

fieldsan object of column names and their values
allowMassAssignOptional, default false If set to true, then even fields that are not set as mass assignable will be set

Returns

Myna.ValidationResult representing the result of this action.

Detail

This function will examine each non-function property of fields and call the corresponding “set” function, if available.  Properties that do not match a “set” function are ignored

saveField

Persists a value to its underlying row

Parameters

fieldNameA column name in the row to savee a value to
newvalThe value to save

Returns

Myna.ValidationResult representing the result of this action.

Detail

This function is normally called from the “set” function, but may be useful when overriding the generated “set” function.

forceDelete

alias for ManagerObject.forceDelete, which passes this bean’s id

getData

returns a structure of this bean’s data

Parameters

depthOptional, default 1 Number of levels of related beans to include in this data.  Set this to 0 to only include this bean’s data Detail: This is a copy of the data, so it will not change when the object is modified

getLabel

getParent

return a bean representing this bean’s parent record

Parameters

columnOptional, default: first foreign key column name in this table to dereference.  Must be a properly defined foreign key in the database

Example

var orderBean = new Myna.DataManager("myapp")
.getManager("orders")
.getById(curOrderId);
var customerBean = orderBean.getParent("customer_id");
Myna.print(customerBean.last_name);

getChildren

return a Myna.DataSet of beans representing this bean’s child records

Parameters

tablename of child table to check for matching rows
columnOptional, default: first exported key to child table column_name to match in child table.  This is only necessary if the child table declares more than one foreign key to this table

Example

var customerBean = new Myna.DataManager("myapp")
.getManager("customers")
.getById(curCustomerId);
var orders = customerBean.getChildren("orders");
Myna.print("Orders Total: " +orders.sumByCol("order_total"));

remove

alias for ManagerObject.remove, which passes this bean’s id

save

Saves a deferred bean and returns a Myna.ValidationResult object

If called against a deferred BeanObject, then validate is called.  If successful, then all values in data are persisted to the database.  Afterwards, this bean’s deferred status is set to the manager’s deferred status

If this bean is not deferred then a successful Myna.ValidationResult is immediately returned

validate

Validates this bean.

Calls all of the validator functions added via ManagerObject.addValidator against this bean and returns the merged Myna.ValidationResult object

Parameters

colnameOptional, default null If defined, limits validation to a single column See:

Properties

exists

true if this bean exists in the database

manager

The ManagerObject that created this bean

dm

The Myna.DataManager object that created this bean

isDirty

true if this bean has unsaved changes, only applies to deferred beans

See

deferred

Default false determines whether “set” operations update the database

If this is set to true, “set” operations on the bean,only update the data property.  Deferred beans only persist to the database when save is called

See

ManagerObject.get ManagerObject.getNew

ds

The datasource name for this bean

data

a simple JS object containing this bean’s data

id

The value of the primary key of this bean

columns

The columns array from Myna.Table.columns for this table

columnNames

The columnNames array from Myna.Table.columnNames for this table

TreeNodeObject

Sub-class of BeanObject generated and returned by <TreeManagerObject.getById>

This class has all the properties of BeanObject, plus tree specific functions

Summary
Functions
moveNodeMoves this node to another location in the tree, only applies to nodes access through <ManagerObject.getTreeManager>
getLeftreturns the value of this node’s “left” property.
getRightreturns the value of this node’s “right” property.
getParentIdreturns the value of this node’s “parent” property.
getParentNodereturns this node’s parent node
isRootNodereturns true if this node is the root node
Properties
childIdsan array of the node ids of this node’s direct children
childNodesan array of the TreeNodes of this node’s direct children
descendantIdsan array of the node ids of all of this node’s descendants
descendantNodesan array of the TreeNodes of all of this node’s descendants
ancestorIdsan array of the node ids of this node’s ancestors
ancestorNodesan array of the TreeNodes of this node’s ancestors

Functions

moveNode

Moves this node to another location in the tree, only applies to nodes access through <ManagerObject.getTreeManager>

Parameters

locationOptional JS object defining where to move this node.  See “Location” below

Location

underNodeOptional, default null The id of the parent node to insert under.  This is unused if beforeNode is defined.  Will append as the last child of underNode
beforeNodeOptional, default null The id of the node before which this node should be inserted Returns: this node

Note

If both underNode and beforeNode are null, then this node will be moved to the last child of the root node.

getLeft

returns the value of this node’s “left” property.

getRight

returns the value of this node’s “right” property.

getParentId

returns the value of this node’s “parent” property.

getParentNode

returns this node’s parent node

isRootNode

returns true if this node is the root node

Properties

childIds

an array of the node ids of this node’s direct children

childNodes

an array of the TreeNodes of this node’s direct children

descendantIds

an array of the node ids of all of this node’s descendants

descendantNodes

an array of the TreeNodes of all of this node’s descendants

ancestorIds

an array of the node ids of this node’s ancestors

ancestorNodes

an array of the TreeNodes of this node’s ancestors

Table data access object generated and returned by Myna.DataManager.getManager
Constructs a ManagerObject for the supplied table.
Provides database metadata and manages Myna.Table objects
This manager’s Myna.Validation instance
A specialized array for working with tabular data
Row data access object generated and returned by ManagerObject.getById
Returns a BeanObject representing a new row not yet inserted
returns either an instance of an existing row or the result of getNew
Creates a record in the database, optionally generating a primary key
Sets multiple fields at once
Table data access object generated and returned by Myna.DataManager.getTreeManager for Modified Pre-order Tree Traversal (MPTT) organized tables
Creates Objects for reading from and writing to database tables
Create modify and delete SQL tables
Structure representing the defined columns in this table, keyed by the column name.
An array of column names, in the order they appear in the table.
A store for validation functions that can be used to validate objects
An extension of getManager that specifically manages Modified Pre-order Tree Traversal (MPTT) organized tables.
Returns a BeanObject representing the row identified by the supplied primary key
Removes a row from the managed table matching the supplied primary key
returns the display label for a column name
Removes or invalidates a row from the managed table matching the supplied primary key
Stores the results of one or more validation operations
Default false determines whether “set” operations update the database
Converts this manager into a TreeManagerObject
Sub-class of BeanObject generated and returned by TreeManagerObject.getById
A DataManager-specific validator that validates a value is unique in a column
add multiple validators to this manager’s validation object
Validates this bean.
adds a validation function to this manager’s validation object
Date or timestamp column to set to current time instead of deleting rows
Sets a “hasOne” relationship with another table.
Sets a “hasMany” relationship with another table.
generates a primary key value
Sql query object Overview: The Query object can be used for queries that return a result set (select statements), as well as those that do not (create, update, insert, delete etc...)
returns an array of primaryKey values that match a search
returns a Myna.DataSet of bean objects that match a search
returns a Myna.DataSet of information from this table
Myna.createUuid=function Myna_createUuid()
Creates a Universally Unique Identifier
String.prototype.titleCap=function()
Capitalizes the first letter of every word in string
Saves a deferred bean and returns a Myna.ValidationResult object
sets an explicit default value for a column
sets several default values at once
returns a structure of all the default values for this table
returns the default value for a column name
sets an explicit display label for a column
generates a display label from a column name
Sets an array of the fields that can be assigned via get, getNew, create and BeanObject.setFields
true if this bean has unsaved changes, only applies to deferred beans
Persists a value to its underlying row
a simple JS object containing this bean’s data