Ext.NET  5.3.0
.NET Component Framework for Enterprise Level Apps
Ext.Net.BelongsToAssociation Class Reference

Represents a many to one association with another model. The owner model is expected to have a foreign key which references the primary key of the associated model: More...

Inheritance diagram for Ext.Net.BelongsToAssociation:
Ext.Net.AbstractAssociation Ext.Net.BaseItem Ext.Net.IAlias Ext.Net.IXObject Ext.Net.IBase

Classes

class  Builder
 
class  Config
 

Public Member Functions

 BelongsToAssociation ()
 
BelongsToAssociation.Builder ToBuilder ()
 
override IControlBuilder ToNativeBuilder ()
 
 BelongsToAssociation (Config config)
 
- Public Member Functions inherited from Ext.Net.AbstractAssociation
virtual void Validate ()
 
- Public Member Functions inherited from Ext.Net.BaseItem
virtual bool HasExplicitValue (string name)
 
void EnsureDataBind ()
 
virtual void Call (string name)
 
virtual void Call (string name, params object[] args)
 
virtual void AddScript (string script)
 
virtual void AddScript (string script, params object[] args)
 
virtual bool IsEmptyObject ()
 
Apply< T > (IApply config)
 
BaseItem Apply (object config)
 
virtual void LoadViewState (object state)
 
virtual object SaveViewState ()
 
virtual void TrackViewState ()
 
void SetDirty ()
 
virtual void DataBind ()
 

Static Public Member Functions

static implicit operator BelongsToAssociation (BelongsToAssociation.Config config)
 

Properties

override string InstanceOf [get]
 
override string Type [get]
 Alias More...
 
virtual string ForeignKey [get, set]
 The name of the foreign key on the owner model that links it to the associated model. Defaults to the lowercased name of the associated model plus "_id", e.g. an association with a model called Product would set up a product_id foreign key. More...
 
virtual string GetterName [get, set]
 The name of the getter function that will be added to the local model's prototype. Defaults to 'get' + the name of the foreign model, e.g. getCategory More...
 
virtual string SetterName [get, set]
 The name of the setter function that will be added to the local model's prototype. Defaults to 'set' + the name of the foreign model, e.g. setCategory More...
 
override ConfigOptionsCollection ConfigOptions [get]
 
- Properties inherited from Ext.Net.AbstractAssociation
override string InstanceOf [get]
 
abstract string Type [get]
 Alias More...
 
virtual string AssociationKey [get, set]
 The name of the property in the data to read the association from. Defaults to the name of the associated model. More...
 
virtual string PrimaryKey [get, set]
 The name of the primary key on the associated model. In general this will be the Ext.data.Model.idProperty of the Model. Defaults to 'id' More...
 
virtual string Model [get, set]
 The string name of the model that is being associated with. Required More...
 
virtual ReaderCollection?? Reader [get]
 A special reader to read associated data More...
 
string PropertyName [get]
 
override ConfigOptionsCollection ConfigOptions [get]
 
- Properties inherited from Ext.Net.BaseItem
virtual string InstanceOf [get]
 
ItemState State [get]
 
virtual DefaultValueMode DefaultValueMode [get, set]
 
virtual bool DesignMode [get]
 
bool AutoDataBind [get, set]
 
ResourceManager ResourceManager [get]
 
virtual Control Owner [get, set]
 The Owner Control for this Listener. More...
 
virtual bool IsDefault [get]
 Does this object currently represent it's default state. More...
 
bool IsTrackingViewState [get]
 
EventHandlerList Events [get]
 
EventHandler DataBinding
 
Control?? BindingContainer [get]
 
virtual ConfigItemCollection?? CustomConfig [get]
 Collection of custom js config More...
 
virtual ConfigOptionsCollection ConfigOptions [get]
 
virtual ConfigOptionsExtraction ConfigOptionsExtraction [get]
 
System.Web.Mvc.HtmlHelper?? HtmlHelper [get, set]
 
- Properties inherited from Ext.Net.IXObject
ConfigOptionsCollection ConfigOptions [get]
 
ConfigOptionsExtraction ConfigOptionsExtraction [get]
 
DefaultValueMode DefaultValueMode [get, set]
 
- Properties inherited from Ext.Net.IAlias
string PropertyName [get]
 

Additional Inherited Members

- Protected Member Functions inherited from Ext.Net.BaseItem
 BaseItem (Control owner)
 
 BaseItem ()
 
virtual void OwnerUpdate (Control owner)
 
virtual void OnDataBinding (EventArgs e)
 

Detailed Description

Represents a many to one association with another model. The owner model is expected to have a foreign key which references the primary key of the associated model:

var Category = Ext.regModel('Category', { fields: [ {name: 'id', type: 'int'}, {name: 'name', type: 'string'} ] });

var Product = Ext.regModel('Product', { fields: [ {name: 'id', type: 'int'}, {name: 'category_id', type: 'int'}, {name: 'name', type: 'string'} ],

associations: [ {type: 'belongsTo', model: 'Category'} ] }); In the example above we have created models for Products and Categories, and linked them together by saying that each Product belongs to a Category. This automatically links each Product to a Category based on the Product's category_id, and provides new functions on the Product model:

Generated getter function

The first function that is added to the owner model is a getter function:

var product = new Product({ id: 100, category_id: 20, name: 'Sneakers' });

product.getCategory(function(category, operation) { //do something with the category object alert(category.get('id')); //alerts 20 }, this); The getCategory function was created on the Product model when we defined the association. This uses the Category's configured proxy to load the Category asynchronously, calling the provided callback when it has loaded.

The new getCategory function will also accept an object containing success, failure and callback properties - callback will always be called, success will only be called if the associated model was loaded successfully and failure will only be called if the associatied model could not be loaded:

product.getCategory({ callback: function(category, operation) {}, //a function that will always be called success : function(category, operation) {}, //a function that will only be called if the load succeeded failure : function(category, operation) {}, //a function that will only be called if the load did not succeed scope : this //optionally pass in a scope object to execute the callbacks in }); In each case above the callbacks are called with two arguments - the associated model instance and the operation object that was executed to load that instance. The Operation object is useful when the instance could not be loaded.

Generated setter function

The second generated function sets the associated model instance - if only a single argument is passed to the setter then the following two calls are identical:

//this call product.setCategory(10);

//is equivalent to this call: product.set('category_id', 10); If we pass in a second argument, the model will be automatically saved and the second argument passed to the owner model's save method:

product.setCategory(10, function(product, operation) { //the product has been saved alert(product.get('category_id')); //now alerts 10 });

//alternative syntax: product.setCategory(10, { callback: function(product, operation), //a function that will always be called success : function(product, operation), //a function that will only be called if the load succeeded failure : function(product, operation), //a function that will only be called if the load did not succeed scope : this //optionally pass in a scope object to execute the callbacks in }) Customisation

Associations reflect on the models they are linking to automatically set up properties such as the primaryKey and foreignKey. These can alternatively be specified:

var Product = Ext.regModel('Product', { fields: [...],

associations: [ {type: 'belongsTo', model: 'Category', primaryKey: 'unique_id', foreignKey: 'cat_id'} ] });

Here we replaced the default primary key (defaults to 'id') and foreign key (calculated as 'category_id') with our own settings. Usually this will not be needed.

Constructor & Destructor Documentation

◆ BelongsToAssociation() [1/2]

Ext.Net.BelongsToAssociation.BelongsToAssociation ( )
inline

◆ BelongsToAssociation() [2/2]

Ext.Net.BelongsToAssociation.BelongsToAssociation ( Config  config)
inline

Member Function Documentation

◆ operator BelongsToAssociation()

static implicit Ext.Net.BelongsToAssociation.operator BelongsToAssociation ( BelongsToAssociation.Config  config)
inlinestatic

◆ ToBuilder()

BelongsToAssociation.Builder Ext.Net.BelongsToAssociation.ToBuilder ( )
inline

◆ ToNativeBuilder()

override IControlBuilder Ext.Net.BelongsToAssociation.ToNativeBuilder ( )
inlinevirtual

Reimplemented from Ext.Net.BaseItem.

Property Documentation

◆ ConfigOptions

override ConfigOptionsCollection Ext.Net.BelongsToAssociation.ConfigOptions
get

◆ ForeignKey

virtual string Ext.Net.BelongsToAssociation.ForeignKey
getset

The name of the foreign key on the owner model that links it to the associated model. Defaults to the lowercased name of the associated model plus "_id", e.g. an association with a model called Product would set up a product_id foreign key.

◆ GetterName

virtual string Ext.Net.BelongsToAssociation.GetterName
getset

The name of the getter function that will be added to the local model's prototype. Defaults to 'get' + the name of the foreign model, e.g. getCategory

◆ InstanceOf

override string Ext.Net.BelongsToAssociation.InstanceOf
get

◆ SetterName

virtual string Ext.Net.BelongsToAssociation.SetterName
getset

The name of the setter function that will be added to the local model's prototype. Defaults to 'set' + the name of the foreign model, e.g. setCategory

◆ Type

override string Ext.Net.BelongsToAssociation.Type
getprotected

Alias


The documentation for this class was generated from the following files: