- General methods
- REST methods
init(obj?: I): this
Clears the model with the method clear()
and then fills according to the passed obj
.
This fill is not the fill(obj)
method so copies every value of obj
except the
protected fields.
clear(): this
Sets all fillable fields and the primary key field to undefined.
clone(): this
Creates a new instance of the class, initializes it with the current instance, copies all parents if any as well and then returns the newly created instance.
Returns with the value of the primary key field.
This getter is called whenever a POST or PUT method is called and the result of this
getter will be sent to the server as the payload. By default this returns whatever
plain()
returns.
plain()
Creates a simple(r) object by copying every fillable field and the primaryValue
to
a new object.
equals(other)
Compares the instance with other
. Every object is considered as equal which has the
same primary value and all values in the fillable fields are equal.
all(options?: any): Observable<this[] | any>
Creates a GET request to load all resources. (e.g. GET /api/users) In case of success all responded items are mapped: a new instance of the class is constructed with each item of the responded list.
If the server responds with paging use page()
instead
page(page?: number|string, options?: any): Observable<P>
Creates a GET request to load a page of all resources. (e.g. GET /api/users?page=2) In case of success all responded items are mapped: a new instance of the class is constructed with each item of the responded list. The paging details are returned.
By default the result list is looked up in the field data
. If the paging response
has a different field name it can be specified by:
protected $pagingItemsKey = 'resultSet';
find(id: number | any, options?: any): Observable<this>
Creates a GET request to load the specified resource. (e.g. GET /api/users/3242). In case of success the responded item is mapped to a class instance.
fresh(options?: any): Observable<this>
Creates a GET request to load the specified resource. (e.g. GET /api/users/3242). In case of success the responded item is used to re-init the current instance.
create(options?: any): Observable<this>
Creates a POST request to insert new data. (e.g. POST /api/users). In case of success the responded item is used to re-init the current instance.
update(options?: any): Observable<this>
Creates a PUT request to update the resource. (e.g. PUT /api/users/3242). In case of success the responded item is used to re-init the current instance.
save(options?: any): Observable<this>
If the instance has primaryValue
update()
is called create()
otherwise.
remove(options?: any): Observable<this>
Creates a DELETE request to remove the resource. (e.g. DELETE /api/users/3242). In case of success the responded item is used to re-init the current instance.
protected onAfterFill(): void
By default this method does nothing. This method is called after every fill()
and init()
.
fill(obj?: any, clearMissing: boolean = false): this
Copies all values of obj
that have fillable field name. If clearMissing
flag is set to true all fields that are fillable but had no value in obj
are
set to null.
addParent(parent: RestModel): this
Sets parent to be a parent of the resource. On URL generation every parent's
itemUrl()
is appended to the base url before appending the resource's route.
Consider Post{id:428} has a parent: User{id:94}. Calling post.update()
will
send a request to PUT /api/users/94/posts/428
.
itemsUrl(): ApiUrlMaker
Returns with an ApiUrlMaker object prepared with API_BASE_URL, all parent
itemUrl
s and $route
(@Path($route)
).
itemUrl(id: number | any = null): ApiUrlMaker
Same as itemsUrl()
but appends one more part: the given id or primaryValue
.