Property | Type | Description | |
---|---|---|---|
$_default_class_addExpression | string | The class used by addField() method. | |
$_default_class_addField | string | The class used by addField() method. | |
$_default_class_hasMany | string | The class used by hasMany() method. | |
$_default_class_hasOne | string | The class used by hasOne() method. | |
$_default_class_join | string | The class used by join() method. | |
$_dirty_after_reload | Save record. | ||
$conditions | array | Conditions list several conditions that must be met by all the records in the associated DataSet. Conditions are stored as elements of array of 1 to 3. Use addCondition() to add new conditions. | |
$data | array | Avoid accessing $data directly, use set() / get() instead. | |
$dirty | array | If the value you set equal to the original value, then the key in this array will be removed. The $dirty data will be reset after you save() the data but it is still available to all before/after save handlers. | |
$id | mixed | Contains ID of the current record. If the value is null then the record is considered to be new. | |
$id_field | string | While in most cases your id field will be called 'id', sometimes you would want to use a different one or maybe don't create field at all. | |
$limit | array | Array of limit set. | |
$load_normalization | boolean | When set to true, loading model from database will also perform value normalization. Use this if you think that persistence may contain badly formatted data that may impact your business logic. | |
$only_fields | false | array | When you have used onlyFields() before loading the data for this model, then only that set of fields will be available. Attempt to access any other field will result in exception. This is to ensure that you do not accidentally access field that you have explicitly excluded. The default behavior is to return NULL and allow you to set new fields even if addField() was not used to set the field. | |
$order | array | Array of set order by. | |
$persistence | Persistence driver inherited from atk4\data\Persistence. | ||
$persistence_data | array | Persistence store some custom information in here that may be useful for them. The key is the name of persistence driver. | |
$reload_after_save | boolean | null | This is to ensure that any SQL-based calculation are executed and updated correctly after you have performed any modifications to the fields. You can set this property to "true" or "false" if you want to explicitly enable or disable reloading. | |
$strict_types | boolean | When set to true, all the field types will be enforced and normalized when setting. | |
$table | string | array | You can define this field as associative array where "key" is used as the name of persistence driver. Here is example for mysql and default: $table = ['user', 'mysql'=>'tbl_user']; | |
$title_field | string | $model->importRows(['Bananas','Oranges']); // 2 records imported |
Property | Type | Description | |
---|---|---|---|
$strict_field_check | boolean | In some situations you want to set field value and then declare it later, then set $strict_field_check = false, but it's not recommended. |
Method | Description | |
---|---|---|
__clone ( ) | ||
__construct ( |
Creation of the new model can be done in two ways:. | |
__debugInfo ( ) : array | Returns array with useful debug info for var_dump. | |
_init ( ) | ||
_unset ( string | array $name ) | Remove current field value and use default. | |
action ( string $mode, array $args = [] ) : atk4\dsql\Query | Execute action. | |
addCondition ( mixed $field, mixed $operator = null, mixed $value = null ) | Narrow down data-set of the current model by applying additional condition. There is no way to remove condition once added, so if you need - clone model. | |
addExpression ( string $name, array $defaults ) : Field_Callback | Add expression field. | |
addField ( string $name, array $defaults = [] ) : |
Adds new field into model. | |
addFields ( array $fields = [], array $defaults = [] ) | Adds multiple fields into model. | |
addRef ( string $link, array $callback ) : object | Add generic relation. Provide your own call-back that will return the model. | |
allFields ( ) | Sets that we should select all available fields. | |
asModel ( string $class, array $options = [] ) : |
This will cast Model into another class without loosing state of your active record. | |
atomic ( callable $f ) : mixed | Atomic executes operations within one begin/end transaction, so if the code inside callback will fail, then all of the transaction will be also rolled back. | |
delete ( mixed $id = null ) | Delete record with a specified id. If no ID is specified then current record is deleted. | |
duplicate ( mixed | null $new_id = null ) | Keeps the model data, but wipes out the ID so when you save it next time, it ends up as a new record in the database. | |
each ( string | callable $method ) | Executes specified method or callback for each record in DataSet. | |
export ( array | null $fields = null ) : array | Export DataSet as array of hashes. | |
get ( mixed $field = null ) : mixed | Returns field value. | |
getIterator ( ) : mixed | Returns iterator (yield values). | |
getRef ( string $link ) : |
Return reference field. | |
getRefs ( ) : array | Returns all reference fields. | |
hasMany ( string $link, array $defaults = [] ) : |
Add hasMany field. | |
hasOne ( string $link, array $defaults = [] ) : |
Add hasOne field. | |
hasRef ( string $link ) : |
Return reference field or false if reference field does not exist. | |
import ( $rows ) | Even more faster method to add data, does not modify your current record and will not return anything. | |
init ( ) | Extend this method to define fields of your choice. | |
insert ( array $row ) : mixed | Faster method to add data, that does not modify active record. | |
isDirty ( $fields = [] ) : boolean | Will return true if any of the specified fields are dirty. | |
join ( string $foreign_table, array $defaults = [] ) : |
Creates an objects that describes relationship between multiple tables (or collections). | |
leftJoin ( string $foreign_table, array $defaults = [] ) : |
Left Join support. | |
load ( mixed $id ) | Load model. | |
loadAny ( ) | Load any record. | |
loadBy ( mixed $field, mixed $value ) | Load record by condition. | |
loaded ( ) : boolean | Is model loaded? | |
newInstance ( string $class = null, array $options = [] ) : |
Create new model from the same base class as $this. | |
offsetExists ( string $name ) : boolean | Do field exist? | |
offsetGet ( string $name ) : mixed | Returns field value. | |
offsetSet ( string $name, mixed $val ) | Set field value. | |
offsetUnset ( string $name ) | Redo field value. | |
onlyFields ( array $fields = [] ) | Sets which fields we will select. | |
rawIterator ( ) : Iterator | Returns iterator. | |
ref ( string $link, array $defaults = [] ) : |
Traverse to related model. | |
refLink ( string $link, array $defaults = [] ) : |
Returns model that can be used for generating sub-query actions. | |
refModel ( string $link, array $defaults = [] ) : |
Return related model. | |
reload ( ) | Reload model by taking its current ID. | |
save ( $data = [] ) | ||
saveAndUnload ( array $data = [] ) | Store the data into database, but will never attempt to reload the data. Additionally any data will be unloaded. | |
saveAs ( string $class, array $options = [] ) : |
Saves the current record by using a different model class. This is similar to:. | |
set ( string | array $field, mixed $value = null ) | Set field value. | |
setDefaults ( array $defaults ) | Set default properties of model. | |
setLimit ( integer $count, integer | null $offset = null ) | Set limit of DataSet. | |
setOrder ( mixed $field, boolean | null $desc = null ) | Set order for model records. Multiple calls. | |
tryLoad ( mixed $id ) | Try to load record. | |
tryLoadAny ( ) | Try to load any record. | |
tryLoadBy ( mixed $field, mixed $value ) | Try to load record by condition. | |
unload ( ) | Unload model. | |
withID ( mixed $id ) | Shortcut for using addCondition(id_field, $id). | |
withPersistence ( |
Create new model from the same base class as $this. If you omit $id,then when saving a new record will be created with default ID. |
Method | Description | |
---|---|---|
_hasReference ( string $c, string $link, array $defaults = [] ) : object | Private method. | |
_rawInsert ( |
This is a temporary method to avoid code duplication, but insert / import should be implemented differently. |
Method | Description | |
---|---|---|
normalizeFieldName ( mixed $field ) : string | Normalize field name. |
public __construct ( |
||
$persistence | ||
$defaults | array |
public __debugInfo ( ) : array | ||
return | array |
protected _rawInsert ( |
||
$m | ||
$row | array |
public addExpression ( string $name, array $defaults ) : Field_Callback | ||
$name | string | |
$defaults | array | |
return | Field_Callback |
public getIterator ( ) : mixed | ||
return | mixed |
public newInstance ( string $class = null, array $options = [] ) : |
||
$class | string | |
$options | array | |
return |
public offsetExists ( string $name ) : boolean | ||
$name | string | |
return | boolean |
public onlyFields ( array $fields = [] ) | ||
$fields | array |
public saveAndUnload ( array $data = [] ) | ||
$data | array |
public setDefaults ( array $defaults ) | ||
$defaults | array |
public withPersistence ( |
||
$persistence | ||
$id | mixed | |
$class | string |
public string $_default_class_addExpression | ||
return | string |
public string $_default_class_addField | ||
return | string |
public string $_default_class_hasMany | ||
return | string |
public string $_default_class_hasOne | ||
return | string |
public string $_default_class_join | ||
return | string |
public array $conditions | ||
return | array |
public array $data | ||
return | array |
public array $dirty | ||
return | array |
public mixed $id | ||
return | mixed |
public string $id_field | ||
return | string |
public bool $load_normalization | ||
return | boolean |
public false|array $only_fields | ||
return | false | array |
public Persistence,atk4\data $persistence | ||
return |
public array $persistence_data | ||
return | array |
protected bool $strict_field_check | ||
return | boolean |
public bool $strict_types | ||
return | boolean |
public string $title_field | ||
return | string |