Entity

extends Wtf\Root
Abstract
Open source code
Methods Summary
protected
# __getEntityName( )
Get short entity name (without namespace) Helper function, required for lazy load.
public
# __call( string $method = NULL, array $params = array ( ) )
Magic relation getter.

Overrides

public
# getScheme( )
Get entity scheme.
public
# save( bool $validate = true )
Save entity data in db.
public
# validate( string $method = 'save' )
Validate entity data.
public
# load( mixed $value , string $field = 'id', array $fields = NULL )
Load entity (data from db).
public
# loadAll( array $where = array ( ), bool $assoc = false, array $fields = NULL )
Get all entities from db.
public
# loadRelation( string $name )
Load realated entity by relation name.
public
# has( array $where = array ( ) )
Determine whether the target data existed.
public
# count( array $where = array ( ) )
Get count of items by $where conditions.
public
# delete( )
Delete entity row from db.
abstract public
# getTable( )
Return entity table name.
abstract public
# getValidators( )
Get list of field validations Structure: <code> [ '<method>' => [ '<field_name>' => v::stringType()->length(1, 255), //... ], ]; </code> Example: ['save' => ['name' => v::stringType()->length(1,255)]].
abstract public
# getRelations( )
Return array of entity relations <code> //structure [ 'relation__name' => [ 'entity' => 'another_entity_name', 'type' => 'has_one', //default, other options: has_many 'key' => 'current_entity_key', //optional, default for has_one: <current_entity>_id, for has_many: id 'foreign_key' => 'another_entity_key', //optional, default for has_one: id, for has_many: '<current_entity>_id' 'assoc' => false, //optional, return data arrays instead of objects on "has_many", default: false ], ];. //Example (current entity: blog post, another entity: user) [ 'author' => [ //has_one 'entity' => 'user', 'key' => 'author_id', 'foreign_key' => 'id' ], ]; //Example (same as above, but with default values) [ 'author' => [ 'entity' => 'user', ], ]; //This example can be called like $blogPostEntity->getAuthor() //Example (current entity: user, another entity: blog post) [ 'posts' => [ 'entity' => 'post', 'type' => 'has_many', 'foreign_key' => 'author_id', ], ] //This example can be called like $userEntity->getPosts() </code>
Methods inherited from Wtf\Root
__construct(), __call(), __get(), get(), set(), getData(), setData()
Properties Summary
protected $relationObjects
# array ( )
protected $scheme
# NULL
Properties inherited from Wtf\Root
$container, $data