Package | com.memamsa.airdb |
Class | public class Relater |
Relater
provides a declarative mechanism to specify
associations between Modeler objects.
This method is an alternative (and recommended) way. Its better than using class meta-data, since it does not require any external compiler setting, allows compile-time checking of association code, provides a richer set of options, including the ability to explicitly specify foreign key column names.
The Associator
still forms the basis for accessing and
operating on associations. The Relater
simply provides a
declarative mechanism. In addition to the previously allowed associations
the Relater allows a has_many_through type, specified as a has_many with
additional options.
Options supported (depending on association):
package example.model { dynamic class Post extends Modeler { private static const relations:Relater = new Relater(Post, function(me:Relater):void { me.belongsTo('author', {class_name: 'example.model.Person'}); me.hasMany('comments', {class_name: 'example.model.Comment'}); }); } } var post:Post = Modeler.findery(Post, {id: 3}); trace(post.author.name); // Find comments since 2009-08-01 post.comments.findAll({ select: " strftime("%Y-%m-%d, created_at) as cd", conditions: "cd > '2009-08-01'" });
See also
Method | Defined by | ||
---|---|---|---|
Relater(klass:Class, directive:Function)
Construct a
Relater for a given model. | Relater | ||
belongsTo(name:String, options:Object = null):void
Specify belongs_to relationship.
| Relater | ||
hasAndBelongsToMany(name:String, options:Object = null):void
Specify has_and_belongs_to_many relationship.
| Relater | ||
hasMany(name:String, options:Object = null):void
Specify has_many relationship.
| Relater | ||
hasOne(name:String, options:Object = null):void
Specify a has_one relationship
The foreign_key if specified is the column name within this model schema
to access the target model.
| Relater |
Relater | () | constructor |
public function Relater(klass:Class, directive:Function)
Construct a Relater
for a given model.
klass:Class — The Modeler sub-class whose associations to relate.
|
|
directive:Function — A Function taking in the Relater as a
parameter and returning void . Use association methods on
the Relater object to specify relationships.
function(me:Relater):void { me.hasMany('things', {class_name: 'some.package.ThingClass'}); } |
See also
belongsTo | () | method |
public function belongsTo(name:String, options:Object = null):void
Specify belongs_to relationship.
Parametersname:String — The name of the association, which becomes available as a
property on the Modeler class objects.
|
|
options:Object (default = null ) — An Object hash of options. Recognized options:
|
See also
hasAndBelongsToMany | () | method |
public function hasAndBelongsToMany(name:String, options:Object = null):void
Specify has_and_belongs_to_many relationship.
Parametersname:String — The name of the association, which becomes available as a
property on the Modeler class objects.
|
|
options:Object (default = null ) — An Object hash of options. Recognized options:
|
See also
hasMany | () | method |
public function hasMany(name:String, options:Object = null):void
Specify has_many relationship.
Parametersname:String — The name of the association, which becomes available as a
property on the Modeler class objects.
|
|
options:Object (default = null ) — An Object hash of options. Recognized options:
|
See also
package example.model { dynamic class Person extends Modeler { private static const relations:Relater = new Relater(Post, function(me:Relater):void { me.hasMany('friendships', {foreign_key: 'from_id', class_name: 'example.model.Relationship'}); me.hasMany('friends', {through: 'friendships', foreign_key: 'to_id', class_name: 'example.model.Person'}); }); } }
hasOne | () | method |
public function hasOne(name:String, options:Object = null):void
Specify a has_one relationship The foreign_key if specified is the column name within this model schema to access the target model.
Parametersname:String |
|
options:Object (default = null )
|