Nodejs Object-Oriented MongoDB Manager
Creates an instance of Instance for a given ClassModel.
ParametersName | Type | Description |
---|---|---|
classModel | ClassModel | A ClassModel that the created Instance will be an instance of. |
document | Object | A mongo document retrieved from a database. This parameter should only be used by internal noomman methods. |
Instance - The Instance created with the given classModel and optional document.
ThrowsError Type | Cause |
---|---|
NoommanConstructorError | If no ClassModel is provided. |
NoommanConstructorError | If classModel is not an instance of ClassModel. |
NoommanConstructorError | If classModel is abstract. |
NoommanConstructorError | If given document does not have an _id property. |
NoommanConstructorError | If given document is for an auditable ClassModel but does not have a revision property. |
Will assign the values of any properties on the given object which are attributes or relationships defined on the ClassModel of this instance to this Instance. Any other properties on the given object are ignored.
ParametersName | Type | Description |
---|---|---|
object | Object | An object containing properties whose values should be assigned to this Instance. |
Deletes this Instance from the database.
ParametersName | Type | Description |
---|---|---|
deletePrivilegeMethodParameter | Object | An object containing any parameters needed by a deletePrivilege method. |
Promise<Boolean> - True if Instance is deleted properly.
ThrowsError Type | Cause |
---|---|
NoommanDeleteError | If this Instance has not yet been saved (i.e. is not in the database). |
NoommanDeleteError | If deletePrivilege method returns false for this Instance. |
Use to determine if this instance has been deleted from the database.
ReturnsBoolean - True if instance has been deleted using a delete method. False otherwise.
Used to compare two instances. Checks that this Instance and the given Instance have (exactly) the same ClassModel, id, and values for each attribute and relationship.
ParametersName | Type | Description |
---|---|---|
that | Instance | An Instance to compare this Instance to. |
Boolean - True if the ClassModel, id, and all attributes and relationships are the same for both Instances, false otherwise.
ThrowsError Type | Cause |
---|---|
NoommanArgumentError | If 'that' parameter is not an instance of Instance. |
Determines if this Instance is an Instance of the given ClassModel, or any of its sub-ClassModels.
ParametersName | Type | Description |
---|---|---|
classModel | ClassModel | A ClassModel to check if this is an Instance of. |
Boolean - True if this Instance is an instance of the given ClassModel, or any of its sub-ClassModels.
Defines what it means for a property to be set. Valid values that count as 'set' are as follows: boolean: True or False number: Any value including 0. string: Any thing of type string. Array: Any array with a length greater than 0. Object/Relationship: Any Value
ParametersName | Type | Description |
---|---|---|
propertyName | String | The name of an attribute or relationship to check. |
Boolean - True if the value of the attribute or relationship is considered as set.
Runs applicable readPrivilege methods for this Instance. If each readPrivilege method returns true for this Instance, then this Instance is returned, otherwise null is returned.
ParametersName | Type | Description |
---|---|---|
readPrivilegeMethodParameter | Object | An object containing any parameters that the readPrivilege method(s) may need. |
Promise<Instance> - This Instance if all readPrivilege methods return true, otherwise null.
Saves the current state of this Instance to the database in the proper collection according to its ClassModel.
ReturnsPromise<Instance> - This Instance, if save is successful.
ThrowsError Type | Cause |
---|---|
NoommanSaveError | If this Instance has already been deleted. |
NoommanSaveError | If this Instance has been stripped by stripSensitiveAttributes(). |
NoommanSaveError | If Instance does not pass createPrivilege or updatePrivilege methods. |
NoommanValidationError | If more than one property in a mutex are set. |
NoommanValidationError | If a required property is not set. |
NoommanValidationError | If none of the properties in a required group are set. |
Error | If a custom validation method from the ClassModel fails. |
Use to determine if this instance currently exists in the database.
ReturnsBoolean - True if instance resulted from a database query or if this instance has had a save method complete successfully. False otherwise.
Saves the current state of this Instance to the database in the proper collection according to its ClassModel. Does not do any validation or run crudPrivilege functions, recommended not to be used outside internal noomman methods. The purpose is for use in saving multiple instances at once, and any calling method is expected to have already run validations and crudPrivilege functions.
ReturnsPromise<Instance> - This Instance, if save is successful.
ThrowsError Type | Cause |
---|---|
NoommanSaveError | If this Instance has already been deleted. |
NoommanSaveError | If this Instance has been stripped by stripSensitiveAttributes(). |
Used to determine if this instance has been stripped of sensitive attributes.
ReturnsBoolean - True if this instance has been stripped of sensitive attributes by calling stripSensitiveAttributes().
Will remove any attributes with property sensitive equal to true from this Instance.
Throws an error if this instance is invalid for any reason, including violations of custom validations, required properties, required groups, or mutexes.
ThrowsError Type | Cause |
---|---|
NoommanValidationError | If more than one property in a mutex are set. |
NoommanValidationError | If a required property is not set. |
NoommanValidationError | If none of the properties in a required group are set. |
Error | If a custom validation method from the ClassModel fails. |
Walks a relationship from this Instance, returning the related Instance or Instances.
ParametersName | Type | Description |
---|---|---|
relationshipName | String | The name of the relationship to walk. |
usePreviousState | Boolean | If true, will walk the previous value of the given relationship for this Instance. For noomman internal use only. |
Promise<Instance | InstanceSet> - The Instance (if relationship is singular) or InstanceSet (if the relationship is non-singular) related to this Instance through the given relationship. If relationship is empty, then null will be returned for singular relationships or an empty InstanceSet will be returned for non-singular relationships.
ThrowsError Type | Cause |
---|---|
NoommanArgumentError | If no relationshipName is given. |
NoommanArgumentError | If relationshipName is not a String. |
NoommanArgumentError | If relationshipName does not match any relationship for the ClassModel of this Instance. |
Walks a path of multiple relationships from this Instance, returning an InstanceSet containing all Instances at the end of the path.
ParametersName | Type | Description |
---|---|---|
path | Array<String> | An Array containing the names of the relationships to walk. |
Promise<InstanceSet> - The InstanceSet of Instances related to this Instance through the given relationships. If there are no Instances at the end of the path, or path cannot be walked all the way to the end, the returned InstanceSet will be empty.
ThrowsError Type | Cause |
---|---|
NoommanArgumentError | If path is not an Array. |
NoommanArgumentError | If path contains any items that are not a string. |
NoommanArgumentError | If path contains any items that are not a valid relationship for the relavant ClassModel. |