API Docs for:
Show:

Collection Class

collection model of one model

Methods

$include

(
  • [options]
)
Promise(BaseModel)

include all relational models and returns new model

Parameters:

  • [options] Object optional
    • [async=true] Boolean optional

      get async values

    • [props] Array(String) optional

      include only given props

Returns:

Promise(BaseModel):

new model

$set

() BaseModel

set value to prop and create a new model

Returns:

BaseModel:

this

$unset

(
  • prop
)
BaseModel

unset property and create a new model

Parameters:

  • prop String

    property name

Returns:

BaseModel:

this

add

(
  • ...items
)
public

add new submodel to item(s)

Parameters:

add

(
  • ...items
)
Collection public

add submodels and create new collection

Parameters:

Returns:

addItem

(
  • item
)
protected

add item to @items

Parameters:

addItems

(
  • items
)
protected

Parameters:

  • items Object | Array(BaseModel | Object)

clear

()

removes all items and ids

clear

()

removes all items and create a new collection

clone

() BaseModel

clone the model as a plain object

Returns:

copyWith

() BaseModel

shallow copy the model with props

Returns:

deprecated

(
  • methodName
  • message
)
Error protected

Show indication message of deprecated method

Parameters:

  • methodName String
  • message String

Returns:

Error:

diff

(
  • plainObj
  • [options]
)
Array(String) public

Get diff props

Parameters:

  • plainObj Any
  • [options] Object optional
    • [ignores] Array(String) optional

      prop names to skip checking diff

Returns:

Array(String):

enum

() Object(key: String => Number) public

Returns:

Object(key: String => Number):

equals

(
  • vo
)
Boolean

check equality

Parameters:

Returns:

Boolean:

error

(
  • reason
  • [message]
)
Error

create instance of DomainError

Parameters:

  • reason String

    reason of the error

  • [message] String optional

Returns:

Error:

every

(
  • fn
  • _this
)
Boolean public

Returns if every items match the condition in given function

Parameters:

  • fn Function
  • _this Object

Returns:

Boolean:

filter

(
  • fn
  • _this
)
Array public

Filter items with given function

Parameters:

  • fn Function
  • _this Object

Returns:

Array:

forEach

(
  • fn
  • _this
)
public

Execute given function for each item

Parameters:

  • fn Function
  • _this Object

getDiff

(
  • plainObj
  • [options]
)
Object public

Get diff prop values

Parameters:

  • plainObj Any
  • [options] Object optional
    • [ignores] Array(String) optional

      prop names to skip checking diff

Returns:

Object:

getFacade

() Facade deprecated

Inherited from Base: /home/ubuntu/base-domain/src/lib/base.coffee:81

Deprecated: just use this.facade

Get facade

Returns:

getItemModelClass

() Function

get item model

Returns:

Function:

getModelProps

() ModelProps private

Returns:

getModule

() BaseModule

Get module which this class belongs to

Returns:

getParent

() Function

get parent class

Returns:

Function:

include

(
  • [options]
)
Promise(BaseModel)

include all relational models if not set

Parameters:

  • [options] Object optional
    • [async=true] Boolean optional

      get async values

    • [props] Array(String) optional

      include only given props

Returns:

Promise(BaseModel):

self

included

() Boolean

Check if all subentities are included.

Returns:

Boolean:

inherit

(
  • anotherModel
)
BaseModel

inherit value of anotherModel

Parameters:

Returns:

BaseModel:

this

loaded

() Boolean public

Returns:

Boolean:

map

(
  • fn
  • _this
)
Array public

Execute given function for each item returns an array of the result

Parameters:

  • fn Function
  • _this Object

Returns:

Array:

plainClone

() Object public

clone the model as a plain object

Returns:

Object:

setEnum

(
  • prop
  • value
)
private

set enum value

Parameters:

  • prop String
  • value String | Number

setIds

(
  • ids
)
chainable

clear and set ids.

Parameters:

  • ids Array(String | Number)

setItems

(
  • items
)

clear and add items

Parameters:

  • items Object | Array(BaseModel | Object)

setRoot

() protected

some

(
  • fn
  • _this
)
Boolean public

Returns if some items match the condition in given function

Parameters:

  • fn Function
  • _this Object

Returns:

Boolean:

toArray

() Array public

export items to Array

Returns:

Array:

toPlainArray

() Array

create plain array.

Returns:

Array:

plainArray

toPlainObject

() Object

create plain object. if this dict contains entities, returns their ids if this dict contains non-entity models, returns their plain objects

Returns:

Object:

plainObject

unset

(
  • prop
)
BaseModel

unset property

Parameters:

  • prop String

    property name

Returns:

BaseModel:

this

Properties

itemFactory

FactoryInterface

item factory Created only one time. Be careful that @root is not changed even the collection's root is changed.

itemModelName

String protected static

model name of the item

items

Object

items (submodel collection)

length

Number public

the number of items (or ids when @isItemEntity is true)