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

Represents a one 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.HasOneAssociation:
Ext.Net.AbstractAssociation Ext.Net.BaseItem Ext.Net.IAlias Ext.Net.IXObject Ext.Net.IBase

Classes

class  Builder
 
class  Config
 

Public Member Functions

 HasOneAssociation ()
 
HasOneAssociation.Builder ToBuilder ()
 
override IControlBuilder ToNativeBuilder ()
 
 HasOneAssociation (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 HasOneAssociation (HasOneAssociation.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" 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. getAddress 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. setAddress 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 one 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:

Ext.define('Address', { extend: 'Ext.data.Model', fields: [ { name: 'id', type: 'int' }, { name: 'number', type: 'string' }, { name: 'street', type: 'string' }, { name: 'city', type: 'string' }, { name: 'zip', type: 'string' }, ] });

Ext.define('Person', { extend: 'Ext.data.Model', fields: [ { name: 'id', type: 'int' }, { name: 'name', type: 'string' }, { name: 'address_id', type: 'int'} ], // we can use the hasOne shortcut on the model to create a hasOne association associations: { type: 'hasOne', model: 'Address' } }); In the example above we have created models for People and Addresses, and linked them together by saying that each Person has a single Address. This automatically links each Person to an Address based on the Persons address_id, and provides new functions on the Person model:

Generated getter function

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

var person = new Person({ id: 100, address_id: 20, name: 'John Smith' });

person.getAddress(function(address, operation) { // do something with the address object alert(address.get('id')); // alerts 20 }, this); The getAddress function was created on the Person model when we defined the association. This uses the Persons configured proxy to load the Address asynchronously, calling the provided callback when it has loaded.

The new getAddress 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:

person.getAddress({ reload: true, // force a reload if the owner model is already cached callback: function(address, operation) {}, // a function that will always be called success : function(address, operation) {}, // a function that will only be called if the load succeeded failure : function(address, 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.

Once the getter has been called on the model, it will be cached if the getter is called a second time. To force the model to reload, specify reload: true in the options object.

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... person.setAddress(10);

// is equivalent to this call: person.set('address_id', 10); An instance of the owner model can also be passed as a parameter.

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:

person.setAddress(10, function(address, operation) { // the address has been saved alert(address.get('address_id')); //now alerts 10 });

//alternative syntax: person.setAddress(10, { callback: function(address, operation), // a function that will always be called success : function(address, operation), // a function that will only be called if the load succeeded failure : function(address, 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:

Ext.define('Person', { fields: [...],

associations: [ { type: 'hasOne', model: 'Address', primaryKey: 'unique_id', foreignKey: 'addr_id' } ] }); Here we replaced the default primary key (defaults to 'id') and foreign key (calculated as 'address_id') with our own settings. Usually this will not be needed.

Constructor & Destructor Documentation

◆ HasOneAssociation() [1/2]

Ext.Net.HasOneAssociation.HasOneAssociation ( )
inline

◆ HasOneAssociation() [2/2]

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

Member Function Documentation

◆ operator HasOneAssociation()

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

◆ ToBuilder()

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

◆ ToNativeBuilder()

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

Reimplemented from Ext.Net.BaseItem.

Property Documentation

◆ ConfigOptions

override ConfigOptionsCollection Ext.Net.HasOneAssociation.ConfigOptions
get

◆ ForeignKey

virtual string Ext.Net.HasOneAssociation.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"

◆ GetterName

virtual string Ext.Net.HasOneAssociation.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. getAddress

◆ InstanceOf

override string Ext.Net.HasOneAssociation.InstanceOf
get

◆ SetterName

virtual string Ext.Net.HasOneAssociation.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. setAddress

◆ Type

override string Ext.Net.HasOneAssociation.Type
getprotected

Alias


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