本文整理汇总了PHP中ActiveRecord::getRecord方法的典型用法代码示例。如果您正苦于以下问题:PHP ActiveRecord::getRecord方法的具体用法?PHP ActiveRecord::getRecord怎么用?PHP ActiveRecord::getRecord使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ActiveRecord
的用法示例。
在下文中一共展示了ActiveRecord::getRecord方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: associatedRecords
public function associatedRecords(ActiveRecord $Record)
{
$referenceRecord = $Record->getRecord();
$foreignKey = $this->_Association->getDefinition('foreignKey');
if (is_null($referenceRecord[$foreignKey])) {
return array(null);
}
// The record has a foreign key, but has not the associated Active Record.
// First try to find the Active Record in the pool, if not query it.
$relatedRecord = ActiveRecordManager::findActiveRecordInPool($this->_Association->getModel(), $referenceRecord[$foreignKey]);
if ($relatedRecord === false) {
$relatedRecord = $this->_Association->getModel()->find('first', array('conditions' => array($this->_Association->getPrimaryKey() => $referenceRecord[$foreignKey]), 'recursive' => -1, 'activeRecord' => false));
if ($relatedRecord) {
$relatedRecord = ActiveRecordManager::getActiveRecord($this->_Association->getModel(), $relatedRecord);
} else {
$relatedRecord = null;
}
}
return array($relatedRecord);
}
示例2: associatedRecords
public function associatedRecords(ActiveRecord $Record)
{
$record = $Record->getRecord();
$Model = $Record->getModel();
$RelatedRecord = false;
// If the association has no condition, try first to find it in the pool
if ($this->_Association->getDefinition('conditions')) {
$RelatedRecord = ActiveRecordManager::findActiveRecordInPoolWithSecondaryKey($this->_Association->getModel(), $this->_Association->getDefinition('foreignKey'), $record[$Model->primaryKey]);
}
if ($RelatedRecord !== false) {
return array($RelatedRecord);
}
if (!$Model->Behaviors->attached('Containable')) {
$Model->Behaviors->load('Containable');
}
$result = $Model->find('first', array('conditions' => array($Model->alias . '.' . $Model->primaryKey => $record[$Model->primaryKey]), 'contain' => array($this->_Association->getName()), 'activeRecord' => false));
if (!empty($result[$this->_Association->getName()][$this->_Association->getPrimaryKey()])) {
$RelatedRecord = ActiveRecordManager::getActiveRecord($this->_Association->getModel(), $result[$this->_Association->getName()]);
} else {
$RelatedRecord = null;
}
return array($RelatedRecord);
}
示例3: removeAssociatedRecord
public function removeAssociatedRecord(ActiveRecord $Record, $resetKeys = true)
{
$checked = false;
$record =& $Record->getRecord();
foreach ($this->_associated as $key => $AssociatedRecord) {
$associatedRecord =& $AssociatedRecord->getRecord();
if ($associatedRecord === $record) {
$checked = true;
break;
}
}
if (!$checked) {
return;
}
unset($this->_associated[$key]);
$this->_AssociationStrategy->removeAssociatedRecord($Record);
if ($resetKeys) {
$this->_associated = array_values($this->_associated);
}
$this->_changed = true;
}
示例4: _removeOldAssociation
/**
* if the record is associated with another record and this record
* not the same as referenced record: find this record, and remove the association
*
* @see AssociationsTest::testCrossAssociation
*
* @param ActiveRecord $Record
* @param ActiveRecord $ReferenceRecord
* @param string $foreignKey
* @return void
*/
protected function _removeOldAssociation(ActiveRecord $Record, ActiveRecord $ReferenceRecord, $foreignKey)
{
$foreignKeyValue = $Record->getRecord()[$foreignKey];
if (empty($foreignKeyValue)) {
return;
}
$AssociatedRecord = ActiveRecordManager::findActiveRecordInPool($this->_Association->getRecord()->getModel(), $foreignKeyValue);
if (!$AssociatedRecord || $ReferenceRecord === $AssociatedRecord) {
return;
}
$assoctiation = $AssociatedRecord->{$this->_Association->getName()};
if ($assoctiation) {
$assoctiation->remove($Record);
}
}