Db_Relation Class
This class lets you use relationships between Db two or many tables. You can pass all parameters to create single relation or pass an array of Db_Relations as first argument and they will be used together to build up an aggregate Db_Relation.
Constructor
Db_Relation
-
$table_name
-
[$foreign_key=null]
-
[$foreign_table=null]
-
[$join_type='LEFT']
Parameters:
-
$table_name
String | ArrayThe name of main table in relation OR array of Db_Relations
-
[$foreign_key=null]
Array optionalForeign key for relation an associative array of local => foreign field names, for example:
-
[$foreign_table=null]
String optionalTable to relate to
-
[$join_type='LEFT']
String optionalType of join to use
Example:
array('user.id' => 't.userId', 'i.item_id' => 't.item_id')
Item Index
Methods
Properties
Methods
compile
()
Before being used, a relation has to be compiled. Compiling finds the root table and levels from the root table, so joins can be constructed from the relation.
getLevel
-
$index
Returns a level of relations, from 1 to however many.
Level 0 is the root table of the relation.
The next level is all tables that have a foreign key to the root table.
And so forth.
This is the order they should appear in JOIN statements,
for the statements to make sense.
Parameters:
-
$index
Integer
Returns:
getRelations
()
Array
Returns the array of Db_Relations this Db_Relation consists of. If null or empty, that means this Db_Relation is not a container.
Returns:
getRootTable
()
String
Returns the root table name, i.e. the unique foreign table that has no foreign key coming out of it.
Returns:
Properties
$levels
Array
Level 0 is the root table. This array contains the other levels... 1 through n where a table is on level k if there is a foreign key from it to a table on level k-1, and not to any other tables on levels below k-1.
$relations
Array
protected
The sub-relations comprising this relation
$was_compiled
Boolean
protected
Whether the relation has been compiled yet.