Packageorg.restfulx.controllers
Classpublic class ModelsController
InheritanceModelsController Inheritance flash.events.EventDispatcher

Provides high level CRUD functionality. This class is responsible for resolving Model dependencies on index and show invocations and hooking up appropriate ServiceProvider methods with their corresponding CacheController methods.



Public Properties
 PropertyDefined by
  cache : CacheController
internal cache of fetched model instances maps model FQNs to ModelsCollections of instances
ModelsController
  errors : IServiceErrors
Exposes errors reported by a service provider.
ModelsController
  state : ModelsMetadata
encapsulates models control metadata and state
ModelsController
Public Methods
 MethodDefined by
  
ModelsController(models:Array)
Creates a new instance of the controller.
ModelsController
  
cached(clazz:Class):ModelsCollection
Get current cache representation for a particular model class.
ModelsController
  
create(object:Object, optsOrOnSuccess:Object = null, onFailure:Function = null, nestedBy:Array = null, metadata:Object = null, recursive:Boolean = false, targetServiceId:int = -1, customProcessor:Function = null, unmarshallDisconnected:Boolean = false):void
Perform REST create operation.
ModelsController
  
destroy(object:Object, optsOrOnSuccess:Object = null, onFailure:Function = null, nestedBy:Array = null, metadata:Object = null, recursive:Boolean = false, targetServiceId:int = -1, customProcessor:Function = null, unmarshallDisconnected:Boolean = false):void
Perform REST destroy operation.
ModelsController
  
index(clazz:Class, optsOrOnSuccess:Object = null, onFailure:Function = null, nestedBy:Array = null, metadata:Object = null, fetchDependencies:Boolean = true, useLazyMode:Boolean = true, append:Boolean = false, targetServiceId:int = -1, customProcessor:Function = null, unmarshallDisconnected:Boolean = false):ModelsCollection
Perform REST index operation.
ModelsController
  
indexAll(... models):void
A shortcut to index multiple models at once.
ModelsController
  
indexed(... models):Boolean
Checks to see if specified models have been index
ModelsController
  
reload(object:Object, optsOrOnSuccess:Object = null, onFailure:Function = null, nestedBy:Array = null, metadata:Object = null, fetchDependencies:Boolean = true, useLazyMode:Boolean = true, append:Boolean = false, targetServiceId:int = -1, customProcessor:Function = null, unmarshallDisconnected:Boolean = false):void
Force reload of a particular model instance or the entire model cache.
ModelsController
  
reloadAll(... models):void
A shortcut to reload multiple models at once.
ModelsController
  
reset(object:Object = null, hard:Boolean = false):void
Resets model metadata.
ModelsController
  
show(object:Object, optsOrOnSuccess:Object = null, onFailure:Function = null, nestedBy:Array = null, metadata:Object = null, fetchDependencies:Boolean = true, useLazyMode:Boolean = false, targetServiceId:int = -1, customProcessor:Function = null, unmarshallDisconnected:Boolean = false):RxModel
Perform REST show operation.
ModelsController
  
showById(clazz:Class, id:Object, optsOrOnSuccess:Function = null, onFailure:Array = null, nestedBy:Object = null, metadata:Boolean = null, fetchDependencies:Boolean = true, useLazyMode:int = false, targetServiceId:Function = -1, customProcessor:Boolean = null, unmarshallDisconnected:* = false):RxModel
A different take on show method.
ModelsController
  
shown(object:Object, id:* = null):Boolean
Checks to see if specified model has been shown
ModelsController
  
update(object:Object, optsOrOnSuccess:Object = null, onFailure:Function = null, nestedBy:Array = null, metadata:Object = null, recursive:Boolean = false, targetServiceId:int = -1, customProcessor:Function = null, unmarshallDisconnected:Boolean = false):void
Perform REST update operation.
ModelsController
Property detail
cacheproperty
public var cache:CacheController

internal cache of fetched model instances maps model FQNs to ModelsCollections of instances

errorsproperty 
public var errors:IServiceErrors

Exposes errors reported by a service provider. This typically happens as a result of Rx.models.create or Rx.models.update call and gives the back-end service (such as RubyOnRails or Merb) to validate incoming data and report any errors back to Flex/AIR client.

This property can be used as the source for data binding.


Example
Here's an example of how to use Rx.errors in your application. Let's say you have an MXML component that provides a sign-up form:
     <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" height="400" width="300" 
       xmlns:validators="org.restfulx.validators.quot;>
       <!-- Proxies for Rails Validators -->
       <validators:ServiceErrorValidator id="signUpLoginNameValidator" field="login" listener="{signUpUsername}" 
          serviceErrors="{Rx.errors}"/>
       <validators:ServiceErrorValidator id="signUpPasswordValidator" field="password" listener="{signUpPassword}" 
          serviceErrors="{Rx.errors}"/>
       <mx:Form>
         <mx:FormItem label="Username" required="true">
            <mx:TextInput id="signUpUsername" width="190"/>
         </mx:FormItem>
         <mx:FormItem label="Email" required="true">
            <mx:TextInput id="signUpEmail" width="190"/>
           </mx:FormItem>
         <mx:FormItem label="Password" required="true">
            <mx:TextInput id="signUpPassword" width="190" displayAsPassword="true"/>
          </mx:FormItem>
       </mx:Form>
     </mx:Canvas>
     

When you perform an actual CRUD action on the object that binds to this form, all errors that have been reported by the service provider will be automatically displayed on the appropriate form fields:
     private function signUp():void {
       var account:Account = new Account;
       account.login = signUpUsername.text;
       account.password = signUpPassword.text;
       account.create();
     }
     

stateproperty 
public var state:ModelsMetadata

encapsulates models control metadata and state

Constructor detail
ModelsController()constructor
public function ModelsController(models:Array)

Creates a new instance of the controller.

Parameters
models:Array — the array of model classes to register e.g. [Model1, Model2]
Method detail
cached()method
public function cached(clazz:Class):ModelsCollection

Get current cache representation for a particular model class.

Parameters
clazz:Class — model class to look up

Returns
ModelsCollection
create()method 
public function create(object:Object, optsOrOnSuccess:Object = null, onFailure:Function = null, nestedBy:Array = null, metadata:Object = null, recursive:Boolean = false, targetServiceId:int = -1, customProcessor:Function = null, unmarshallDisconnected:Boolean = false):void

Perform REST create operation.

Parameters
object:Object — object to create
 
optsOrOnSuccess:Object (default = null) — if this is a Function or an IResponder, we treat it as a callback to invoke when the service returns; otherwise, we treat it as an anonymous Object of key/value pairs which can be used to clober the value of any subsequent parameters.
 
onFailure:Function (default = null) — callback function invoked if service call fails
 
nestedBy:Array (default = null) — an array of model instances that should used to nest this request under
 
metadata:Object (default = null) — an object (a hash of key value pairs that should be tagged on to the request)
 
recursive:Boolean (default = false) — service provider to use
 
targetServiceId:int (default = -1) — if provided then it will be used instead of the standard service provider workflow, this allows you to fully customize create processing. This function should have the same signature as IServiceProvider#create
 
customProcessor:Function (default = null)
 
unmarshallDisconnected:Boolean (default = false)

See also


Example
       Rx.models.create(project); // project is an instance variable of a model class
     

destroy()method 
public function destroy(object:Object, optsOrOnSuccess:Object = null, onFailure:Function = null, nestedBy:Array = null, metadata:Object = null, recursive:Boolean = false, targetServiceId:int = -1, customProcessor:Function = null, unmarshallDisconnected:Boolean = false):void

Perform REST destroy operation. For example:

Parameters
object:Object — object to destroy
 
optsOrOnSuccess:Object (default = null) — if this is a Function or an IResponder, we treat it as a callback to invoke when the service returns; otherwise, we treat it as an anonymous Object of key/value pairs which can be used to clober the value of any subsequent parameters.
 
onFailure:Function (default = null) — callback function invoked if service call fails
 
nestedBy:Array (default = null) — an array of model instances that should used to nest this request under
 
metadata:Object (default = null) — an object (a hash of key value pairs that should be tagged on to the request)
 
recursive:Boolean (default = false) — service provider to use
 
targetServiceId:int (default = -1) — if provided then it will be used instead of the standard service provider workflow, this allows you to fully customize destroy processing. This function should have the same signature as IServiceProvider#destroy
 
customProcessor:Function (default = null)
 
unmarshallDisconnected:Boolean (default = false)

See also


Example
       Rx.models.destroy(project); // project is an instance variable of a model class
     

index()method 
public function index(clazz:Class, optsOrOnSuccess:Object = null, onFailure:Function = null, nestedBy:Array = null, metadata:Object = null, fetchDependencies:Boolean = true, useLazyMode:Boolean = true, append:Boolean = false, targetServiceId:int = -1, customProcessor:Function = null, unmarshallDisconnected:Boolean = false):ModelsCollection

Perform REST index operation.

Parameters
clazz:Class — the Class to index
 
optsOrOnSuccess:Object (default = null) — if this is a Function or an IResponder, we treat it as a callback to invoke when the service returns; otherwise, we treat it as an anonymous Object of key/value pairs which can be used to clober the value of any subsequent parameters.
 
onFailure:Function (default = null) — callback function to call if the service call fails
 
nestedBy:Array (default = null) — an array of model instances that should used to nest this request under
 
metadata:Object (default = null) — an object (a hash of key value pairs that should be tagged on to the request)
 
fetchDependencies:Boolean (default = true) — if true model dependencies will be recursively fetched as well
 
useLazyMode:Boolean (default = true) — if true dependencies marked with [Lazy] will be skipped (not fetched)
 
append:Boolean (default = false) — if true then target ModelsCollection will not be reset but just appended to (default is to reset)
 
targetServiceId:int (default = -1) — service provider to use
 
customProcessor:Function (default = null) — if provided then it will be used instead of the standard service provider workflow, this allows you to fully customize index processing. This function should have the same signature as IServiceProvider#index
 
unmarshallDisconnected:Boolean (default = false) — if true then the unmarshaller will not try to link up the result with other items in the cache

Returns
ModelsCollection

Example
       Rx.models.index(Project);
     

Note that the following two method calls are equivalent:
       Rx.models.index(Project, myOnSuccess, [company]);
       Rx.models.index(Project, {onSuccess:myOnSuccessFunction, nestedBy:[company]});
     

This means that you can specify arguments in order (which means you'll have to provide arguments for all parameters even if you really just want to specify the last one for example) or you can specify them selectively.

In order to specify arguments selectively you can use the {} syntax and then refer to the arguments by name.

indexAll()method 
public function indexAll(... models):void

A shortcut to index multiple models at once. Useful if you don't want to define any special options, such as callbacks, metadata, etc.

Parameters
... models — a list of models to index
indexed()method 
public function indexed(... models):Boolean

Checks to see if specified models have been index

Parameters
... models — of models

Returns
Boolean — true if all the models have been indexed, false otherwise

Example
      Rx.models.indexed(Project, Task, RandomStuff) // true of false
     

reload()method 
public function reload(object:Object, optsOrOnSuccess:Object = null, onFailure:Function = null, nestedBy:Array = null, metadata:Object = null, fetchDependencies:Boolean = true, useLazyMode:Boolean = true, append:Boolean = false, targetServiceId:int = -1, customProcessor:Function = null, unmarshallDisconnected:Boolean = false):void

Force reload of a particular model instance or the entire model cache.

Parameters
object:Object — model instance or model Class reference to reload
 
optsOrOnSuccess:Object (default = null) — if this is a Function or an IResponder, we treat it as a callback to invoke when the service returns; otherwise, we treat it as an anonymous Object of key/value pairs which can be used to clober the value of any subsequent parameters.
 
onFailure:Function (default = null) — callback function invoked if service call fails
 
nestedBy:Array (default = null) — an array of model instances that should used to nest this request under
 
metadata:Object (default = null) — an object (a hash of key value pairs that should be tagged on to the request)
 
fetchDependencies:Boolean (default = true) — if true model dependencies will be recursively fetched as well
 
useLazyMode:Boolean (default = true) — if true dependencies marked with [Lazy] will be skipped (not fetched)
 
append:Boolean (default = false) — set this to true if you don't want to nuke target ModelsCollection
 
targetServiceId:int (default = -1) — service provider to use
 
customProcessor:Function (default = null) — if provided then it will be used instead of the standard service provider workflow, this allows you to fully customize index/show processing. This function should have the same signature as IServiceProvider#index/show
 
unmarshallDisconnected:Boolean (default = false)
reloadAll()method 
public function reloadAll(... models):void

A shortcut to reload multiple models at once. Useful if you don't want to define any special options, such as callbacks, metadata, etc.

Parameters
... models — a list of models to reload
reset()method 
public function reset(object:Object = null, hard:Boolean = false):void

Resets model metadata.

Parameters
object:Object (default = null) — can be a model class or specific model instance
 
hard:Boolean (default = false)

See also

org.restfulx.models.ModelsStateMetadata.reset
show()method 
public function show(object:Object, optsOrOnSuccess:Object = null, onFailure:Function = null, nestedBy:Array = null, metadata:Object = null, fetchDependencies:Boolean = true, useLazyMode:Boolean = false, targetServiceId:int = -1, customProcessor:Function = null, unmarshallDisconnected:Boolean = false):RxModel

Perform REST show operation.

Parameters
object:Object — object to show
 
optsOrOnSuccess:Object (default = null) — if this is a Function or an IResponder, we treat it as a callback to invoke when the service returns; otherwise, we treat it as an anonymous Object of key/value pairs which can be used to clober the value of any subsequent parameters.
 
onFailure:Function (default = null) — callback function which is invoked if there are errors during service call
 
nestedBy:Array (default = null) — an array of model instances that should used to nest this request under
 
metadata:Object (default = null) — an object (a hash of key value pairs that should be tagged on to the request)
 
fetchDependencies:Boolean (default = true) — if true model dependencies will be recursively fetched as well
 
useLazyMode:Boolean (default = false) — if true dependencies marked with [Lazy] will be skipped (not fetched)
 
targetServiceId:int (default = -1) — service provider to use
 
customProcessor:Function (default = null) — if provided then it will be used instead of the standard service provider workflow, this allows you to fully customize show processing. This function should have the same signature as IServiceProvider#show
 
unmarshallDisconnected:Boolean (default = false)

Returns
RxModel

See also


Example
       Rx.models.show(project); // project is an instance variable of a model class
     

showById()method 
public function showById(clazz:Class, id:Object, optsOrOnSuccess:Function = null, onFailure:Array = null, nestedBy:Object = null, metadata:Boolean = null, fetchDependencies:Boolean = true, useLazyMode:int = false, targetServiceId:Function = -1, customProcessor:Boolean = null, unmarshallDisconnected:* = false):RxModel

A different take on show method.

Parameters
clazz:Class
 
id:Object
 
optsOrOnSuccess:Function (default = null)
 
onFailure:Array (default = null)
 
nestedBy:Object (default = null)
 
metadata:Boolean (default = null)
 
fetchDependencies:Boolean (default = true)
 
useLazyMode:int (default = false)
 
targetServiceId:Function (default = -1)
 
customProcessor:Boolean (default = null)
 
unmarshallDisconnected:* (default = false)

Returns
RxModel

Example
You can perform a show operation using Class and id instead of instance variable
      Rx.models.showById(Project, "123123");
     

shown()method 
public function shown(object:Object, id:* = null):Boolean

Checks to see if specified model has been shown

Parameters
object:Object — of models
 
id:* (default = null)

Returns
Boolean — true if all the models have been indexed, false otherwise

Example
      Rx.models.shown(Project, "123123") // true of false
      
      // Or
      
      Rx.models.shown(project);
     

update()method 
public function update(object:Object, optsOrOnSuccess:Object = null, onFailure:Function = null, nestedBy:Array = null, metadata:Object = null, recursive:Boolean = false, targetServiceId:int = -1, customProcessor:Function = null, unmarshallDisconnected:Boolean = false):void

Perform REST update operation. For example: Rx.models.update(project);

Parameters
object:Object — object to update
 
optsOrOnSuccess:Object (default = null) — if this is a Function or an IResponder, we treat it as a callback to invoke when the service returns; otherwise, we treat it as an anonymous Object of key/value pairs which can be used to clober the value of any subsequent parameters.
 
onFailure:Function (default = null) — an array of model instances that should used to nest this request under
 
nestedBy:Array (default = null) — an object (a hash of key value pairs that should be tagged on to the request)
 
metadata:Object (default = null) — service provider to use
 
recursive:Boolean (default = false) — if provided then it will be used instead of the standard service provider workflow, this allows you to fully customize update processing. This function should have the same signature as IServiceProvider#update
 
targetServiceId:int (default = -1)
 
customProcessor:Function (default = null)
 
unmarshallDisconnected:Boolean (default = false)

See also