API Docs for: 0.0.3
Show:

Model Class

Extends CoreObject
Defined in: src/Model.coffee:8

Available since 0.0.2

Used to manipulate records of a given type. Use modelFactory to get an instance related to a Database.

Constructor

Model

()

Defined in src/Model.coffee:8

Available since 0.0.2

Methods

_attachEvents

() private chainable

Defined in src/Model.coffee:197

Available since 0.0.2

Attach events on the store

_databaseClass

() Object private static

Defined in src/Model.coffee:316

Available since 0.0.2

Return the Database class, used to avoid cross-referencing packages

Returns:

Object:

the Database class

_detachEvents

() private chainable

Defined in src/Model.coffee:217

Available since 0.0.2

Detach events if previously attached to the store

_emit

(
  • event
  • [args]
)
private

Defined in src/Model.coffee:271

Available since 0.0.2

Emits an event from ourself or our database if we have one

Parameters:

  • event String

    name of the event

  • [args] Mixed optional multiple

    any additional args to pass to the event handlers

_modelName

(
  • name
)
String private static

Defined in src/Model.coffee:301

Available since 0.0.2

Normalize a model name

Parameters:

  • name String

    name of the model to normalize

Returns:

String:

the normalized model name

_recordCreated

(
  • record
)
private

Defined in src/Model.coffee:233

Available since 0.0.2

Handles the record.created event

Parameters:

  • record Object

    the created record

_recordDeleted

(
  • record
)
private

Defined in src/Model.coffee:258

Available since 0.0.2

Handles the record.deleted event

Parameters:

  • record Object

    the deleted record

_recordUpdated

(
  • record
)
private

Defined in src/Model.coffee:245

Available since 0.0.2

Handles the record.updated event

Parameters:

  • record Object

    the updated record

assert

(
  • expression
  • message
)
chainable

Inherited from CoreObject: src/CoreObject.coffee:103

Available since 0.0.2

Make an assertion and throw an error if it fails

Parameters:

  • expression Boolean

    the test to assert true

  • message String

    the message of the error if assertion is failing

assertValidModelName

(
  • name
)
static chainable

Defined in src/Model.coffee:287

Available since 0.0.2

Asserts that the given model name is valid

Parameters:

  • name String

    name of the model to check

className

() String

Inherited from CoreObject: src/CoreObject.coffee:78

Available since 0.0.2

Returns the name of the class for this object

Returns:

String:

class name of this object

constructor

(
  • database
  • name
  • store
)

Defined in src/Model.coffee:53

Available since 0.0.2

Constructs a new instance of Model

Parameters:

  • database Database | Null

    our database

  • name String | Null

    our name

  • store RecordStore

    our store

count

() Number

Defined in src/Model.coffee:172

Available since 0.0.2

Count all records

Returns:

Number:

the total count of all records

create

(
  • [record={}]
)
Object

Defined in src/Model.coffee:84

Available since 0.0.2

Creates a new record

Parameters:

  • [record={}] Object optional

    the attributes of our record, including a possible id if we want to force it

Returns:

Object:

copy of our new record

delete

(
  • id
)
Object

Defined in src/Model.coffee:109

Available since 0.0.2

Deletes a record

Parameters:

Returns:

Object:

copy of the old record which has been deleted

destroy

()

Inherited from CoreObject but overwritten in src/Model.coffee:183

Available since 0.0.2

Destroy this instance, freeing the store

find

(
  • id
)
Object | Undefined

Defined in src/Model.coffee:121

Available since 0.0.2

Find a record given its id

Parameters:

Returns:

Object | Undefined:

copy of the record, or undefined if no such record

findAll

() Array

Defined in src/Model.coffee:148

Available since 0.0.2

Find all records in the store for this model

Returns:

Array:

array of all records

findMany

(
  • id
)
Array

Defined in src/Model.coffee:133

Available since 0.0.2

Find multiple records at once given their id

Parameters:

  • id Array | Number | String multiple

    id list of the records to get, or one array with all of them

Returns:

Array:

array of all records found

findQuery

(
  • filter
  • [thisArg]
)
Array

Defined in src/Model.coffee:159

Available since 0.0.2

Find multiple records using a filter object or function

Parameters:

  • filter Object | Function

    the object with attributes to match, or a function used to filter records

  • [thisArg] Object optional

    the object to bind filter on if it's a function

Returns:

Array:

array of all records which matched

identify

() String

Inherited from CoreObject: src/CoreObject.coffee:143

Available since 0.0.2

Get a string identification of the object

Returns:

String:

the string identifying the object

lockProperties

(
  • names
)
chainable

Inherited from CoreObject: src/CoreObject.coffee:117

Available since 0.0.2

Lock given properties so that setting them will fail

Parameters:

  • names String multiple

    the name of each property to lock

log

(
  • [level="debug"]
  • items
)
chainable

Inherited from CoreObject: src/CoreObject.coffee:89

Available since 0.0.2

Log a string with the class name as a prefix

Parameters:

  • [level="debug"] String optional

    level (debug, notice, info, warning, error, danger or fatal)

  • items Mixed multiple

    anything to give back to the logger

update

(
  • [id]
  • record
)
Object

Defined in src/Model.coffee:96

Available since 0.0.2

Update a record with new given attributes

Parameters:

  • [id] String | Number optional

    id of the record to update, if not given, it must be defined in record.id

  • record Object

    attributes to update

Returns:

Object:

copy of the updated record

uuid

() String

Inherited from CoreObject: src/CoreObject.coffee:131

Available since 0.0.2

Get the UUID of the object or fail if none defined

Returns:

String:

UUID of the object

Properties

_database

Database private

Defined in src/Model.coffee:35

Available since 0.0.2

Our database object where we came from

_eventListeners

Object private

Defined in src/Model.coffee:43

Available since 0.0.2

Store our event listener methods that have been self-bound for detaching later

_name

String private

Defined in src/Model.coffee:27

Available since 0.0.2

Name of our model, normalized

_store

RecordStore | MergedRecordStore private

Defined in src/Model.coffee:18

Available since 0.0.2

Holds our store, could be a MergedRecordStore or a simple RecordStore