-
Notifications
You must be signed in to change notification settings - Fork 3
ActiveRecord
Florent Gouget edited this page Feb 16, 2016
·
3 revisions
Classes inheriting ActiveRecord are your business object.
Method Name | Params | Method Description |
---|---|---|
constructor | $injector: the angular injector rootUrl: string for the rootUrl specified when configuring the services options: when creating from existing object | This method is designed to be used internally. It is called from the Dao when calling the create method. Dao will ensure that $injector and rootUrl are correctly passed. |
build | options: the object to build from | Ensure that the ActiveRecord instance will be correctly built If some of the fields are nested ActiveRecords, they will be built as well. Empty arrays will be initialized if necessary The build method also ensure that if you are refreshing an existing object with less information (eg fields not populated on refresh), the most precise values will be kept. This is useful when saving objects. We want to have the latest values returned by the server but have no way to ask for a populated object to be returned, so we have to sort out what to keep. |
clone | Returns a new instance of this AR, with the same values but no _id | |
buildField | model: the field information registered in the mongoose schema value: the value to be put in the field | In the Generic version, just returns a cloned value of the field. Override this method to perform custom operations on some fields when creating. |
archive/restore | DO NOT USE . Custom business code. Shouldn't be here | |
delete | Performs a DELETE http query | |
populate | field: String, the name of the field to populate | If field is a nested ActiveRecord that has not yet be populated (eg just an id), calling populate('field') will perform the http query needed to retrieve the full object, build it, and set the field with the new object. If the field is already populated, does nothing Returns a promise anyway, resolved when the request is over |
beforeSave | Creates and returns an object to be passed to the save() method. Ensures nested objects are reduced to their id, dates are correctly formatted, and so on. If you override this, make sure to return such an object |
|
save | populate | performs save query (put an existing object or post a new one, according on whether the object has an _id). If populate is set, will perform another GET query to retrieve the latest state of the object, with populated nested fields. Otherwise will update the object with whatever is returned from the save call. |