本文整理汇总了PHP中TActiveRecord::getRecordGateway方法的典型用法代码示例。如果您正苦于以下问题:PHP TActiveRecord::getRecordGateway方法的具体用法?PHP TActiveRecord::getRecordGateway怎么用?PHP TActiveRecord::getRecordGateway使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TActiveRecord
的用法示例。
在下文中一共展示了TActiveRecord::getRecordGateway方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: findForeignKeys
/**
* 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.
* @param TActiveRecord $fromRecord
* @param TActiveRecord $matchesRecord
* @return array foreign keys with source column names as key and foreign column names as value.
*/
protected function findForeignKeys($from, $matchesRecord, $loose = false)
{
$gateway = $matchesRecord->getRecordGateway();
$recordTableInfo = $gateway->getRecordTableInfo($matchesRecord);
$matchingTableName = strtolower($recordTableInfo->getTableName());
$matchingFullTableName = strtolower($recordTableInfo->getTableFullName());
$tableInfo = $from;
if ($from instanceof TActiveRecord) {
$tableInfo = $gateway->getRecordTableInfo($from);
}
//find first non-empty FK
foreach ($tableInfo->getForeignKeys() as $fkeys) {
$fkTable = strtolower($fkeys['table']);
if ($fkTable === $matchingTableName || $fkTable === $matchingFullTableName) {
$hasFkField = !$loose && $this->getContext()->hasFkField();
$key = $hasFkField ? $this->getFkFields($fkeys['keys']) : $fkeys['keys'];
if (!empty($key)) {
return $key;
}
}
}
//none found
$matching = $gateway->getRecordTableInfo($matchesRecord)->getTableFullName();
throw new TActiveRecordException('ar_relations_missing_fk', $tableInfo->getTableFullName(), $matching);
}