Class M.ModelAttribute
Extends
M.Object.
M.ModelAttribute encapsulates all meta information about a model record's property:
* is it required?
* what data type is it of? (important for mapping to relational database schemas)
* what validators shall be applied
All M.ModelAttributes for a model record are saved under M.Model#__meta property of a model.
Each ModelAttribute is saved with the record properties name as key.
That means:
model.record[propA] is the value of the property.
model.__meta[propA] is the M.ModelAttribute object for the record property.
Defined in: model_attribute.js.
Constructor Attributes | Constructor Name and Description |
---|---|
Field Attributes | Field Name and Description |
---|---|
The data type for the model record property.
|
|
Indicates whether this property is required to be set before persisting.
|
|
Indicates whether an update has been performed on this property with the set method or not.
|
|
Record properties that define references have their referenced entity saved here.
|
|
The type of this object.
|
|
Array containing all validators for this model record property.
|
Method Attributes | Method Name and Description |
---|---|
<static> |
M.ModelAttribute.attr(dataType, opts)
Returns a model attribute.
|
validate(obj)
Iterates over validators array and calls validate on each validator with the param object passed to the validator.
|
Field Detail
{String}
dataType
The data type for the model record property.
Extremely important e.g. to map model to relational database table.
{Boolean}
isRequired
Indicates whether this property is required to be set before persisting.
If YES, then automatically @link M.PresenceValidator is added to the property, to check the presence.
{Boolean}
isUpdated
Indicates whether an update has been performed on this property with the set method or not.
{Object}
refEntity
Record properties that define references have their referenced entity saved here.
{String}
type
The type of this object.
{Object}
validators
Array containing all validators for this model record property.
E.g. [@link M.PresenceValidator, @link M.NumberValidator]
Method Detail
<static>
{Object}
M.ModelAttribute.attr(dataType, opts)
Returns a model attribute.
- Parameters:
- dataType
- The data type of the attribute: e.g. String
- opts
- options for the attribute, such as defaultValue, isRequired flag, etc. ...
- Returns:
- {Object} M.ModelAttribute object
{Boolean}
validate(obj)
Iterates over validators array and calls validate on each validator with the param object passed to the validator.
- Parameters:
- {Object} obj
- The parameter object containing the model id, the record as M.ModelAttribute object and the value of the property.
- Returns:
- {Boolean} Indicates wheter the property is valid (YES|true) or invalid (NO|false).