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

Represents a one-to-many relationship between two models. Usually created indirectly via a model definition: More...

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

Classes

class  Builder
 
class  Config
 

Public Member Functions

 HasManyAssociation ()
 
HasManyAssociation.Builder ToBuilder ()
 
override IControlBuilder ToNativeBuilder ()
 
 HasManyAssociation (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 HasManyAssociation (HasManyAssociation.Config config)
 

Properties

override string InstanceOf [get]
 
override string Type [get]
 Alias More...
 
virtual bool AutoLoad [get, set]
 True to automatically load the related store from a remote source when instantiated. Defaults to false. More...
 
virtual string FilterProperty [get, set]
 Optionally overrides the default filter that is set up on the associated Store. If this is not set, a filter is automatically created which filters the association based on the configured foreignKey. See intro docs for more details. Defaults to undefined More...
 
virtual string ForeignKey [get, set]
 The name of the foreign key on the associated model that links it to the owner model. Defaults to the lowercased name of the owner model plus "_id", e.g. an association with a where a model called Group hasMany Users would create 'group_id' as the foreign key. More...
 
virtual string Name [get, set]
 The name of the function to create on the owner model to retrieve the child store. If not specified, the pluralized name of the child model is used. More...
 
virtual Store StoreConfig [get, set]
 Optional configuration object that will be passed to the generated Store. Defaults to undefined. More...
 
virtual string StoreConfigProxy [get]
 
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 one-to-many relationship between two models. Usually created indirectly via a model definition:

Ext.regModel('Product', { fields: [ {name: 'id', type: 'int'}, {name: 'user_id', type: 'int'}, {name: 'name', type: 'string'} ] });

Ext.regModel('User', { fields: [ {name: 'id', type: 'int'}, {name: 'name', type: 'string'} ],

hasMany: {model: 'Product', name: 'products'} });

Above we created Product and User models, and linked them by saying that a User hasMany Products. This gives us a new function on every User instance, in this case the function is called 'products' because that is the name we specified in the association configuration above.

This new function returns a specialized Store which is automatically filtered to load only Products for the given model instance:

//first, we load up a User with id of 1 var user = Ext.ModelManager.create({id: 1, name: 'Ed'}, 'User');

//the user.products function was created automatically by the association and returns a Store //the created store is automatically scoped to the set of Products for the User with id of 1 var products = user.products();

//we still have all of the usual Store functions, for example it's easy to add a Product for this User products.add({ name: 'Another Product' });

//saves the changes to the store - this automatically sets the new Product's user_id to 1 before saving products.sync(); The new Store is only instantiated the first time you call products() to conserve memory and processing time, though calling products() a second time returns the same store instance.

Custom filtering

The Store is automatically furnished with a filter - by default this filter tells the store to only return records where the associated model's foreign key matches the owner model's primary key. For example, if a User with ID = 100 hasMany Products, the filter loads only Products with user_id == 100.

Sometimes we want to filter by another field - for example in the case of a Twitter search application we may have models for Search and Tweet:

var Search = Ext.regModel('Search', { fields: [ 'id', 'query' ],

hasMany: { model: 'Tweet', name : 'tweets', filterProperty: 'query' } });

Ext.regModel('Tweet', { fields: [ 'id', 'text', 'from_user' ] });

//returns a Store filtered by the filterProperty var store = new Search({query: 'Sencha Touch'}).tweets(); The tweets association above is filtered by the query property by setting the filterProperty, and is equivalent to this:

var store = new Ext.data.Store({ model: 'Tweet', filters: [ { property: 'query', value : 'Sencha Touch' } ] });

Constructor & Destructor Documentation

◆ HasManyAssociation() [1/2]

Ext.Net.HasManyAssociation.HasManyAssociation ( )
inline

◆ HasManyAssociation() [2/2]

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

Member Function Documentation

◆ operator HasManyAssociation()

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

◆ ToBuilder()

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

◆ ToNativeBuilder()

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

Reimplemented from Ext.Net.BaseItem.

Property Documentation

◆ AutoLoad

virtual bool Ext.Net.HasManyAssociation.AutoLoad
getset

True to automatically load the related store from a remote source when instantiated. Defaults to false.

◆ ConfigOptions

override ConfigOptionsCollection Ext.Net.HasManyAssociation.ConfigOptions
get

◆ FilterProperty

virtual string Ext.Net.HasManyAssociation.FilterProperty
getset

Optionally overrides the default filter that is set up on the associated Store. If this is not set, a filter is automatically created which filters the association based on the configured foreignKey. See intro docs for more details. Defaults to undefined

◆ ForeignKey

virtual string Ext.Net.HasManyAssociation.ForeignKey
getset

The name of the foreign key on the associated model that links it to the owner model. Defaults to the lowercased name of the owner model plus "_id", e.g. an association with a where a model called Group hasMany Users would create 'group_id' as the foreign key.

◆ InstanceOf

override string Ext.Net.HasManyAssociation.InstanceOf
get

◆ Name

virtual string Ext.Net.HasManyAssociation.Name
getset

The name of the function to create on the owner model to retrieve the child store. If not specified, the pluralized name of the child model is used.

◆ StoreConfig

virtual Store Ext.Net.HasManyAssociation.StoreConfig
getset

Optional configuration object that will be passed to the generated Store. Defaults to undefined.

◆ StoreConfigProxy

virtual string Ext.Net.HasManyAssociation.StoreConfigProxy
getprotected

◆ Type

override string Ext.Net.HasManyAssociation.Type
getprotected

Alias


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