## Class TActiveRecordRelation

Description

Base class for active record relationships.

- abstract:
- since: 3.1
- version: $Id$
- author: Wei Zhuo <weizho[at]gmail[dot]com>

Located in /Data/ActiveRecord/Relations/TActiveRecordRelation.php (line 26)

Direct descendents

Class | Description
--- | ---
TActiveRecordBelongsTo | Implements the foreign key relationship (TActiveRecord::BELONGS_TO) between the source objects and the related foreign object. Consider the entity relationship between a Team and a Player.
TActiveRecordHasMany | Implements TActiveRecord::HAS_MANY relationship between the source object having zero or more foreign objects. Consider the entity relationship between a Team and a Player.
TActiveRecordHasManyAssociation | Implements the M-N (many to many) relationship via association table.
TActiveRecordHasOne | TActiveRecordHasOne models the object relationship that a record (the source object) property is an instance of foreign record object having a foreign key related to the source object. The HAS_ONE relation is very similar to the HAS_MANY relationship (in fact, it is equivalent in the entities relationship point of view).

Method Summary
TActiveRecordRelation __construct (TActiveRecordRelationContext $context, mixed $criteria)
void collectForeignObjects (mixed &$results)
boolean fetchResultsInto (mixed $obj)
array findForeignKeys (mixed $from, TActiveRecord $matchesRecord, [mixed $loose = false], TActiveRecord $fromRecord)
TActiveRecord[] findForeignObjects (array $fields, array $indexValues)
TActiveRecordRelationContext getContext ()
TActiveRecordCriteria getCriteria ()
array getIndexValues (array $keys, array $results)
string getObjectHash (mixed $obj, array $properties)
array getRelationForeignKeys ()
TActiveRecord getSourceRecord ()
void populateResult (array &$results, array $properties, array &$fkObjects, array $fields)
void setObjectProperty (TActiveRecord $source, array $properties, array &$collections)
void setResultCollection (array &$results, array &$collections, array $properties)
mixed __call (string $method, array $args)
Methods
Constructor __construct (line 31)

- access: public

TActiveRecordRelation __construct (TActiveRecordRelationContext $context, mixed $criteria)
collectForeignObjects (line 61)

- access: protected
- abstract:

void collectForeignObjects (mixed &$results)

Redefined in descendants as:

- TActiveRecordBelongsTo::collectForeignObjects() : Get the foreign key index values from the results and make calls to the database to find the corresponding foreign objects.
- TActiveRecordHasMany::collectForeignObjects() : Get the foreign key index values from the results and make calls to the database to find the corresponding foreign objects.
- TActiveRecordHasManyAssociation::collectForeignObjects() : Get the foreign key index values from the results and make calls to the database to find the corresponding foreign objects using association table.
- TActiveRecordHasOne::collectForeignObjects() : Get the foreign key index values from the results and make calls to the database to find the corresponding foreign objects.

fetchResultsInto (line 97)

Fetch results for current relationship.

- return: always true.
- access: public

boolean fetchResultsInto (mixed $obj)
findForeignKeys (line 111)

Returns foreign keys in $fromRecord with source column names as key and foreign column names in the corresponding $matchesRecord as value.

The method returns the first matching foreign key between these 2 records.

- return: foreign keys with source column names as key and foreign column names as value.
- access: protected

array findForeignKeys (mixed $from, TActiveRecord $matchesRecord, [mixed $loose = false], TActiveRecord $fromRecord)

- TActiveRecord $fromRecord
- TActiveRecord $matchesRecord

findForeignObjects (line 182)

Fetches the foreign objects using TActiveRecord::findAllByIndex()

- return: foreign objects.
- access: protected

TActiveRecord[] findForeignObjects (array $fields, array $indexValues)

- array $fields: field names
- array $indexValues: foreign key index values.

getContext (line 40)

- access: protected

TActiveRecordRelationContext getContext ()
getCriteria (line 48)

- access: protected

TActiveRecordCriteria getCriteria ()
getIndexValues (line 194)

Obtain the foreign key index values from the results.

- return: foreign key index values.
- access: protected

array getIndexValues (array $keys, array $results)

- array $keys: property names
- array $results: TActiveRecord results

getObjectHash (line 168)

- return: object hash using crc32 and serialize.
- access: protected

string getObjectHash (mixed $obj, array $properties)

- mixed $obj: object or array to be hashed
- array $properties: name of property for hashing the properties.

getRelationForeignKeys (line 143)

- return: foreign key field names as key and object properties as value.
- access: public
- abstract:
- since: 3.1.2

array getRelationForeignKeys ()

Redefined in descendants as:

- TActiveRecordBelongsTo::getRelationForeignKeys()
- TActiveRecordHasMany::getRelationForeignKeys()
- TActiveRecordHasManyAssociation::getRelationForeignKeys()
- TActiveRecordHasOne::getRelationForeignKeys()

getSourceRecord (line 56)

- access: protected

TActiveRecord getSourceRecord ()
populateResult (line 216)

Populate the results with the foreign objects found.

- access: protected

void populateResult (array &$results, array $properties, array &$fkObjects, array $fields)

- array &$results: source results
- array $properties: source property names
- array &$fkObjects: foreign objects
- array $fields: foreign object field names.

setObjectProperty (line 247)

Sets the foreign objects to the given property on the source object.

- access: protected

void setObjectProperty (TActiveRecord $source, array $properties, array &$collections)

- TActiveRecord $source: source object.
- array $properties: source properties
- array &$collections: foreign objects.

Redefined in descendants as:

- TActiveRecordBelongsTo::setObjectProperty() : Sets the foreign objects to the given property on the source object.
- TActiveRecordHasOne::setObjectProperty() : Sets the foreign objects to the given property on the source object.

setResultCollection (line 230)

Populates the result array with foreign objects (matched using foreign key hashed property values).

- access: protected

void setResultCollection (array &$results, array &$collections, array $properties)

- array $results
- array $collections
- array $properties: property names

__call (line 74)

Dispatch the method calls to the source record finder object. When an instance of TActiveRecord or an array of TActiveRecord is returned the corresponding foreign objects are also fetched and assigned.

Multiple relationship calls can be chain together.

- return: TActiveRecord or array of TActiveRecord results depending on the method called.
- access: public

mixed __call (string $method, array $args)

- string $method: method name called
- array $args: method arguments

Documentation generated on Mon, 22 Feb 2010 12:16:35 +0000 by phpDocumentor 1.3.0RC4