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

Consider the entity relationship between Articles and Categories via the association table Article_Category. +---------+ +------------------+ +----------+ | Article | * -----> * | Article_Category | * <----- * | Category | +---------+ +------------------+ +----------+ Where one article may have 0 or more categories and each category may have 0 or more articles. We may model Article-Category object relationship as active record as follows. class ArticleRecord { const TABLE='Article'; public $article_id; public $Categories=array(); //foreign object collection. public static $RELATIONS = array ( 'Categories' => array(self::MANY_TO_MANY, 'CategoryRecord', 'Article_Category') ); public static function finder($className=__CLASS__) { return parent::finder($className); } } class CategoryRecord { const TABLE='Category'; public $category_id; public $Articles=array(); public static $RELATIONS = array ( 'Articles' => array(self::MANY_TO_MANY, 'ArticleRecord', 'Article_Category') ); public static function finder($className=__CLASS__) { return parent::finder($className); } } The static $RELATIONS property of ArticleRecord defines that the property $Categories has many CategoryRecords. Similar, the static $RELATIONS property of CategoryRecord defines many ArticleRecords. The articles with categories list may be fetched as follows. $articles = TeamRecord::finder()->withCategories()->findAll(); The method with_xxx() (where xxx is the relationship property name, in this case, Categories) fetchs the corresponding CategoryRecords using a second query (not by using a join). The with_xxx() accepts the same arguments as other finder methods of TActiveRecord.
부터: 3.1
상속: extends TActiveRecordRelation
파일 보기 프로젝트 열기: pradosoft/prado

공개 메소드들

메소드 설명
createCommand ( $criteria, $foreignKeys, $indexValues, $sourceKeys )
getRelationForeignKeys ( ) : array
updateAssociatedRecords ( ) : boolean Updates the associated foreign objects.

보호된 메소드들

메소드 설명
collectForeignObjects ( &$results ) Get the foreign key index values from the results and make calls to the database to find the corresponding foreign objects using association table.
createFkObject ( $type, $row, $foreignKeys ) : TActiveRecord
fetchForeignObjects ( &$results, $foreignKeys, $indexValues, $sourceKeys ) Fetches the foreign objects using TActiveRecord::findAllByIndex()
getAssociationJoin ( $foreignKeys, $indexValues, $sourceKeys ) : string SQL inner join for M-N relationship via association table.
getAssociationTable ( ) : TDbTableInfo
getAssociationTableCommandBuilder ( ) : TDbCommandBuilder
getCommandBuilder ( ) : TDataGatewayCommand
getForeignCommandBuilder ( ) : TDataGatewayCommand
getForeignTable ( ) : TDbTableInfo
getSourceColumns ( $sourceKeys ) : string
getSourceTable ( ) : TDbTableInfo

비공개 메소드들

메소드 설명
addAssociationData ( $builder, $data )
getForeignObjectValues ( $foreignKeys, $fkObject )
getSourceRecordValues ( $obj )
hasAssociationData ( $builder, $data )
updateAssociationTable ( $obj, $fkObjects, $builder )

메소드 상세

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.
protected collectForeignObjects ( &$results )

createCommand() 공개 메소드

public createCommand ( $criteria, $foreignKeys, $indexValues, $sourceKeys )

createFkObject() 보호된 메소드

protected createFkObject ( $type, $row, $foreignKeys ) : TActiveRecord
리턴 Prado\Data\ActiveRecord\TActiveRecord

fetchForeignObjects() 보호된 메소드

Fetches the foreign objects using TActiveRecord::findAllByIndex()
protected fetchForeignObjects ( &$results, $foreignKeys, $indexValues, $sourceKeys )

getAssociationJoin() 보호된 메소드

SQL inner join for M-N relationship via association table.
protected getAssociationJoin ( $foreignKeys, $indexValues, $sourceKeys ) : string
리턴 string inner join condition for M-N relationship via association table.

getAssociationTable() 보호된 메소드

protected getAssociationTable ( ) : TDbTableInfo
리턴 TDbTableInfo association table information.

getAssociationTableCommandBuilder() 보호된 메소드

protected getAssociationTableCommandBuilder ( ) : TDbCommandBuilder
리턴 TDbCommandBuilder

getCommandBuilder() 보호된 메소드

protected getCommandBuilder ( ) : TDataGatewayCommand
리턴 TDataGatewayCommand

getForeignCommandBuilder() 보호된 메소드

protected getForeignCommandBuilder ( ) : TDataGatewayCommand
리턴 TDataGatewayCommand

getForeignTable() 보호된 메소드

protected getForeignTable ( ) : TDbTableInfo
리턴 TDbTableInfo foreign table information.

getRelationForeignKeys() 공개 메소드

public getRelationForeignKeys ( ) : array
리턴 array 2 arrays of source keys and foreign keys from the association table.

getSourceColumns() 보호된 메소드

protected getSourceColumns ( $sourceKeys ) : string
리턴 string comma separated source column names.

getSourceTable() 보호된 메소드

protected getSourceTable ( ) : TDbTableInfo
리턴 TDbTableInfo source table information.

updateAssociatedRecords() 공개 메소드

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