Class MJoin
The MJoin class provides a one-to-many join link for Editor. This can be useful in cases were an attribute can take multiple values at the same time - for example cumulative security access levels.
Typically the MJoin class should be used with a link table, but this is optional. Please note that if you don't use a link table you should be aware that on edit the linked rows are deleted and then reinserted, thus if any values should be retained they should also be submitted.
Please refer to the Editor .NET documentation for further information https://editor.datatables.net/manual/net
Inheritance
Namespace: DataTables
Assembly: DataTables-Editor-Server.dll
Syntax
public class MJoin : object
Constructors
| Improve this Doc View SourceMJoin(String)
Create an MJoin instance for use with the Editor class's MJoin method.
Declaration
public MJoin(string table)
Parameters
Type | Name | Description |
---|---|---|
System.String | table | Table to join to. |
Methods
| Improve this Doc View SourceField(Field)
Add a new field to the MJoin instance
Declaration
public MJoin Field(Field field)
Parameters
Type | Name | Description |
---|---|---|
Field | field | New field to add |
Returns
Type | Description |
---|---|
MJoin | Self for chaining |
Fields()
Get the list of fields configured for this join instance
Declaration
public List<Field> Fields()
Returns
Type | Description |
---|---|
List<Field> | Join instance fields |
Get()
Get the get flag for this MJoin instance. If disabled data will not be retrieved
Declaration
public Boolean Get()
Returns
Type | Description |
---|---|
Boolean | Enablement status |
Get(Boolean)
Set the get flag for this MJoin instance. If disabled data will not be retrieved when loaded by DataTables.
Declaration
public MJoin Get(bool flag)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | flag | Value to set |
Returns
Type | Description |
---|---|
MJoin | Self for chaining |
LeftJoin(String, String, String, String)
Add a left join condition to the Mjoin instance, allowing it to operate over multiple tables. Multiple
leftJoin()
calls can be made for a
single Mjoin instance to join multiple tables.
Declaration
public MJoin LeftJoin(string table, string field1, string op = null, string field2 = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | table | Table name to do a join onto |
System.String | field1 | Field from the parent table to use as the join link |
System.String | op | Join condition ( |
System.String | field2 | Field from the child table to use as the join link |
Returns
Type | Description |
---|---|
MJoin | Self for chaining |
Link(String, String)
Create a join link between two tables. The order of the fields does not matter, but each field must contain the table name as well as the field name.
This method can be called a maximum of two times for an MJoin instance:
- First time, creates a link between the Editor host table and a join table
- Second time creates the links required for a link table.
Please refer to the Editor MJoin documentation for further details: https://editor.datatables.net/manual/net
Declaration
public MJoin Link(string field1, string field2)
Parameters
Type | Name | Description |
---|---|---|
System.String | field1 | Table and field name |
System.String | field2 | Table and field name |
Returns
Type | Description |
---|---|
MJoin | Self for chaining |
Model<T>()
Set a model to use.
In keeping with the MVC style of coding, you can define the fields and their types that you wish to get from the database in a simple class. Editor will automatically add fields from the model.
Note that fields that are defined in the model can also be defined as
Field
instances should you wish to add additional
options to a specific field such as formatters or validation.
Declaration
public MJoin Model<T>()
Returns
Type | Description |
---|---|
MJoin | Self for chaining |
Type Parameters
Name | Description |
---|---|
T | Model to use |
Name()
Get the JSON name for the join JSON and HTTP submit data.
Declaration
public string Name()
Returns
Type | Description |
---|---|
System.String | JSON name |
Name(String)
Set the JSON name for the join JSON and HTTP submit data. By default this is set to match the table name, but can be altered using this method.
Declaration
public MJoin Name(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | Name to use |
Returns
Type | Description |
---|---|
MJoin | Self for chaining |
Order()
Get the current order string
Declaration
public string Order()
Returns
Type | Description |
---|---|
System.String | SQL order string |
Order(String)
Set the order to apply to the joined data
Declaration
public MJoin Order(string order)
Parameters
Type | Name | Description |
---|---|---|
System.String | order | SQL order string |
Returns
Type | Description |
---|---|
MJoin | Self for chaining |
Set()
Get the set value for this instance. If disabled this MJoin instance will not write to the database
Declaration
public Boolean Set()
Returns
Type | Description |
---|---|
Boolean | Enablement value |
Set(Boolean)
Set the set value for this instance. If disabled this MJoin instance will not write to the database on create, edit or delete.
Declaration
public MJoin Set(bool flag)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | flag | Value to set |
Returns
Type | Description |
---|---|
MJoin | Self for chaining |
Table()
Get the DB table name that this MJoin instance links the main table to
Declaration
public string Table()
Returns
Type | Description |
---|---|
System.String | Table name |
Table(String)
Set the table name that this MJoin instance links the main table to.
Declaration
public MJoin Table(string table)
Parameters
Type | Name | Description |
---|---|---|
System.String | table | Table to link to |
Returns
Type | Description |
---|---|
MJoin | Self for chaining |
Validator(String, Func<Editor, DtRequest.RequestTypes, Dictionary<String, Object>, String>)
Declaration
public MJoin Validator(string fieldName, Func<Editor, DtRequest.RequestTypes, Dictionary<string, object>, string> fn)
Parameters
Type | Name | Description |
---|---|---|
System.String | fieldName | |
Func<Editor, DtRequest.RequestTypes, Dictionary<System.String, System.Object>, System.String> | fn |
Returns
Type | Description |
---|---|
MJoin |
Where(Action<Query>)
Where condition to add to the query used to get data from the database. Multiple conditions can be added if required.
Can be used in two different ways:
- Simple case:
where( field, value, operator )
- Complex:
where( fn )
The simple case is fairly self explanatory, a condition is applied to the
data that looks like field operator value
(e.g. name = 'Allan'
). The
complex case allows full control over the query conditions by providing a
closure function that has access to the database Query that Editor is
using, so you can use the where()
, or_where()
, and_where()
and
where_group()
methods as you require.
Please be very careful when using this method! If an edit made by a user using Editor removes the row from the where condition, the result is undefined (since Editor expects the row to still be available, but the condition removes it from the result set).
Declaration
public MJoin Where(Action<Query> fn)
Parameters
Type | Name | Description |
---|---|---|
Action<Query> | fn | Delegate to execute adding where conditions to the table |
Returns
Type | Description |
---|---|
MJoin | Self for chaining |
Where(String, Object, String)
Where condition to add to the query used to get data from the database. Multiple conditions can be added if required.
Can be used in two different ways:
- Simple case:
where( field, value, operator )
- Complex:
where( fn )
The simple case is fairly self explanatory, a condition is applied to the
data that looks like field operator value
(e.g. name = 'Allan'
). The
complex case allows full control over the query conditions by providing a
closure function that has access to the database Query that Editor is
using, so you can use the where()
, or_where()
, and_where()
and
where_group()
methods as you require.
Please be very careful when using this method! If an edit made by a user using Editor removes the row from the where condition, the result is undefined (since Editor expects the row to still be available, but the condition removes it from the result set).
Declaration
public MJoin Where(string key, dynamic value, string op = "=")
Parameters
Type | Name | Description |
---|---|---|
System.String | key | Database column name to perform the condition on |
System.Object | value | Value to use for the condition |
System.String | op | Conditional operator |
Returns
Type | Description |
---|---|
MJoin | Self for chaining |