PHP Class Lazer\Classes\Core_Relation

Author: Grzegorz Kuźnik
Show file Open project: greg0/lazer-database

Protected Properties

Property Type Description
$keys Relation keys names
$relationType string Current relation type
$relations array All relations types
$tables Tables names

Public Methods

Method Description
belongsTo ( string $table ) : Core_Relation Set relation one2many to table
build ( array $array, string $part ) : array
foreignKey ( string $key ) : Core_Relation Set foreign key name
getJunction ( ) : boolean | string Getter of junction table name in many2many relation
getRelation ( ) : array Get relation information
hasAndBelongsToMany ( string $table ) : Core_Relation Set relation many2many to table
hasMany ( string $table ) : Core_Relation Set relation many2one to table
localKey ( string $key ) : Core_Relation Set local key name
relations ( ) : array Get relations types
removeRelation ( ) Remove relation
setRelation ( ) Set specified relation
table ( string $name ) : Lazer\Classes\Relation Factory method
with ( string $table ) : Core_Relation Use relation to table

Protected Methods

Method Description
addRelation ( ) Add data to configs and create all necessary files
deleteRelationData ( string $from, string $to ) Inserts relation data to config file
insertRelationData ( string $from, string $to, string $type, array $keys ) Inserts relation data to config file
join ( object $row ) : Lazer\Classes\Database Process query with joined data
setKey ( string $type, string $key ) : Core_Relation Set key name
setRelationType ( string $relation ) Set relation type to field
setTable ( string $type, string $name ) Set table name

Method Details

addRelation() protected method

Add data to configs and create all necessary files
protected addRelation ( )

belongsTo() public method

Set relation one2many to table
public belongsTo ( string $table ) : Core_Relation
$table string Table name
return Core_Relation

build() public method

public build ( array $array, string $part ) : array
$array array
$part string
return array

deleteRelationData() protected method

Inserts relation data to config file
protected deleteRelationData ( string $from, string $to )
$from string Local table
$to string Related table

foreignKey() public method

Set foreign key name
public foreignKey ( string $key ) : Core_Relation
$key string key name
return Core_Relation

getJunction() public method

Getter of junction table name in many2many relation
public getJunction ( ) : boolean | string
return boolean | string Name of junction table or false

getRelation() public method

Get relation information
public getRelation ( ) : array
return array relation information

hasAndBelongsToMany() public method

Set relation many2many to table
public hasAndBelongsToMany ( string $table ) : Core_Relation
$table string Table name
return Core_Relation

hasMany() public method

Set relation many2one to table
public hasMany ( string $table ) : Core_Relation
$table string Table name
return Core_Relation

insertRelationData() protected method

Inserts relation data to config file
protected insertRelationData ( string $from, string $to, string $type, array $keys )
$from string Local table
$to string Related table
$type string Relation type
$keys array Relationed keys

join() protected method

Process query with joined data
protected join ( object $row ) : Lazer\Classes\Database
$row object One row of data
return Lazer\Classes\Database

localKey() public method

Set local key name
public localKey ( string $key ) : Core_Relation
$key string key name
return Core_Relation

relations() public static method

Get relations types
public static relations ( ) : array
return array

removeRelation() public method

Remove relation
public removeRelation ( )

setKey() protected method

Set key name
protected setKey ( string $type, string $key ) : Core_Relation
$type string local or foreign
$key string key name
return Core_Relation

setRelation() public method

Set specified relation
public setRelation ( )

setRelationType() protected method

Set relation type to field
protected setRelationType ( string $relation )
$relation string Name of relation

setTable() protected method

Set table name
protected setTable ( string $type, string $name )
$type string local or foreign
$name string table name

table() public static method

Factory method
public static table ( string $name ) : Lazer\Classes\Relation
$name string Name of table
return Lazer\Classes\Relation

with() public method

Use relation to table
public with ( string $table ) : Core_Relation
$table string Table name
return Core_Relation

Property Details

$keys protected property

Relation keys names
protected $keys

$relationType protected property

Current relation type
protected string $relationType
return string

$relations protected static property

All relations types
protected static array $relations
return array

$tables protected property

Tables names
protected $tables