PHP 클래스 Prado\Data\ActiveRecord\Relations\TActiveRecordBelongsTo

+------+ +--------+ | 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 { see TActiveRecordHasMany for detailed definition. } class PlayerRecord extends TActiveRecord { const TABLE='player'; public $player_id; //primary key public $team_name; //foreign key player.team_name <-> team.name public $age; public $team; //foreign object TeamRecord public static $RELATIONS = array ( 'team' => array(self::BELONGS_TO, 'TeamRecord') ); public static function finder($className=__CLASS__) { return parent::finder($className); } } The static $RELATIONS property of PlayerRecord defines that the property $team belongs to a TeamRecord. The team object may be fetched as follows. $players = PlayerRecord::finder()->with_team()->findAll(); The method with_xxx() (where xxx is the relationship property name, in this case, team) fetchs the corresponding TeamRecords 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_team('location = ?', 'Madrid').
부터: 3.1
상속: extends TActiveRecordRelation
파일 보기 프로젝트 열기: pradosoft/prado

공개 메소드들

메소드 설명
getRelationForeignKeys ( ) : array
updateAssociatedRecords ( ) : boolean Updates the source object first.

보호된 메소드들

메소드 설명
collectForeignObjects ( &$results ) Get the foreign key index values from the results and make calls to the database to find the corresponding foreign objects.
setObjectProperty ( $source, $properties, &$collections ) Sets the foreign objects to the given property on the source object.

메소드 상세

collectForeignObjects() 보호된 메소드

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() 공개 메소드

부터: 3.1.2
public getRelationForeignKeys ( ) : array
리턴 array foreign key field names as key and object properties as value.

setObjectProperty() 보호된 메소드

Sets the foreign objects to the given property on the source object.
protected setObjectProperty ( $source, $properties, &$collections )

updateAssociatedRecords() 공개 메소드

Updates the source object first.
public updateAssociatedRecords ( ) : boolean
리턴 boolean true if all update are success (including if no update was required), false otherwise .