PHP Class Prado\Data\ActiveRecord\Relations\TActiveRecordHasMany

+------+ +--------+ | Team | 1 <----- * | Player | +------+ +--------+ Where one team may have 0 or more players and each player belongs to only one team. We may model Team-Player object relationship as active record as follows. class TeamRecord extends TActiveRecord { const TABLE='team'; public $name; //primary key public $location; public $players=array(); //list of players public static $RELATIONS=array ( 'players' => array(self::HAS_MANY, 'PlayerRecord') ); public static function finder($className=__CLASS__) { return parent::finder($className); } } class PlayerRecord extends TActiveRecord { see TActiveRecordBelongsTo for detailed definition } The static $RELATIONS property of TeamRecord defines that the property $players has many PlayerRecords. The players list may be fetched as follows. $team = TeamRecord::finder()->with_players()->findAll(); The method with_xxx() (where xxx is the relationship property name, in this case, players) fetchs the corresponding PlayerRecords using a second query (not by using a join). The with_xxx() accepts the same arguments as other finder methods of TActiveRecord, e.g. with_players('age < ?', 35).
Since: 3.1
Inheritance: extends TActiveRecordRelation
Afficher le fichier Open project: pradosoft/prado

Méthodes publiques

Méthode Description
getRelationForeignKeys ( ) : array
updateAssociatedRecords ( ) : boolean Updates the associated foreign objects.

Méthodes protégées

Méthode Description
collectForeignObjects ( &$results ) Get the foreign key index values from the results and make calls to the database to find the corresponding foreign objects.

Method Details

collectForeignObjects() protected méthode

Get the foreign key index values from the results and make calls to the database to find the corresponding foreign objects.
protected collectForeignObjects ( &$results )

getRelationForeignKeys() public méthode

Since: 3.1.2
public getRelationForeignKeys ( ) : array
Résultat array foreign key field names as key and object properties as value.

updateAssociatedRecords() public méthode

Updates the associated foreign objects.
public updateAssociatedRecords ( ) : boolean
Résultat boolean true if all update are success (including if no update was required), false otherwise .