Model Class
Used to manipulate records of a given type. Use modelFactory to get an instance related to a Database.
Constructor
Model
()
Item Index
Methods
Properties
Methods
_attachEvents
()
private
chainable
Attach events on the store
_databaseClass
()
Object
private
static
Return the Database class, used to avoid cross-referencing packages
Returns:
the Database
class
_detachEvents
()
private
chainable
Detach events if previously attached to the store
_emit
-
event
-
[args]
Emits an event from ourself or our database if we have one
Parameters:
-
event
Stringname of the event
-
[args]
Mixed optional multipleany additional args to pass to the event handlers
_modelName
-
name
Normalize a model name
Parameters:
-
name
Stringname of the model to normalize
Returns:
the normalized model name
_recordCreated
-
record
Handles the record.created
event
Parameters:
-
record
Objectthe created record
_recordDeleted
-
record
Handles the record.deleted
event
Parameters:
-
record
Objectthe deleted record
_recordUpdated
-
record
Handles the record.updated
event
Parameters:
-
record
Objectthe updated record
assert
-
expression
-
message
Make an assertion and throw an error if it fails
assertValidModelName
-
name
Asserts that the given model name is valid
Parameters:
-
name
Stringname of the model to check
className
()
String
Returns the name of the class for this object
Returns:
class name of this object
constructor
-
database
-
name
-
store
Constructs a new instance of Model
create
-
[record={}]
Creates a new record
Parameters:
-
[record={}]
Object optionalthe attributes of our record, including a possible
id
if we want to force it
Returns:
copy of our new record
delete
-
id
Deletes a record
Returns:
copy of the old record which has been deleted
destroy
()
Destroy this instance, freeing the store
find
-
id
Find a record given its id
Returns:
copy of the record, or undefined
if no such record
findAll
()
Array
Find all records in the store for this model
Returns:
array of all records
findMany
-
id
Find multiple records at once given their id
Parameters:
Returns:
array of all records found
findQuery
-
filter
-
[thisArg]
Find multiple records using a filter object or function
Parameters:
Returns:
array of all records which matched
identify
()
String
Get a string identification of the object
Returns:
the string identifying the object
lockProperties
-
names
Lock given properties so that setting them will fail
Parameters:
-
names
String multiplethe name of each property to lock
log
-
[level="debug"]
-
items
Log a string with the class name as a prefix
Parameters:
-
[level="debug"]
String optionallevel (debug, notice, info, warning, error, danger or fatal)
-
items
Mixed multipleanything to give back to the logger
Properties
_eventListeners
Object
private
Store our event listener methods that have been self-bound for detaching later
_store
RecordStore | MergedRecordStore
private
Holds our store, could be a MergedRecordStore or a simple RecordStore