returns the table object for this record.
public getTable ( ) : Doctrine_Table | ||
return | Doctrine_Table | a Doctrine_Table object |
public function fetchRelatedFor(Doctrine_Record $record) { $id = $record->getIncremented(); if (empty($id) || !$this->definition['table']->getAttribute(Doctrine_Core::ATTR_LOAD_REFERENCES)) { return Doctrine_Collection::create($this->getTable()); } else { $q = new Doctrine_RawSql($this->getTable()->getConnection()); $assocTable = $this->getAssociationFactory()->getTableName(); $tableName = $record->getTable()->getTableName(); $identifierColumnNames = $record->getTable()->getIdentifierColumnNames(); $identifier = array_pop($identifierColumnNames); $sub = 'SELECT ' . $this->getForeignRefColumnName() . ' FROM ' . $assocTable . ' WHERE ' . $this->getLocalRefColumnName() . ' = ?'; $condition[] = $tableName . '.' . $identifier . ' IN (' . $sub . ')'; $joinCondition[] = $tableName . '.' . $identifier . ' = ' . $assocTable . '.' . $this->getForeignRefColumnName(); if ($this->definition['equal']) { $sub2 = 'SELECT ' . $this->getLocalRefColumnName() . ' FROM ' . $assocTable . ' WHERE ' . $this->getForeignRefColumnName() . ' = ?'; $condition[] = $tableName . '.' . $identifier . ' IN (' . $sub2 . ')'; $joinCondition[] = $tableName . '.' . $identifier . ' = ' . $assocTable . '.' . $this->getLocalRefColumnName(); } $q->select('{' . $tableName . '.*}, {' . $assocTable . '.*}')->from($tableName . ' INNER JOIN ' . $assocTable . ' ON ' . implode(' OR ', $joinCondition))->where(implode(' OR ', $condition))->orderBy($tableName . '.' . $identifier . ' ASC'); if ($orderBy = $this->getOrderByStatement($tableName, true)) { $q->addOrderBy($orderBy); } $q->addComponent($tableName, $this->getClass()); $path = $this->getClass() . '.' . $this->getAssociationFactory()->getComponentName(); if ($this->definition['refClassRelationAlias']) { $path = $this->getClass() . '.' . $this->definition['refClassRelationAlias']; } $q->addComponent($assocTable, $path); $params = $this->definition['equal'] ? array($id, $id) : array($id); $res = $q->execute($params); return $res; } }
/** * contructor, creates node with reference to record and any options * * @param object $record instance of Doctrine_Record * @param array $options options */ public function __construct(Doctrine_Record $record, $options) { $this->record = $record; $this->options = $options; // Make sure that the tree object of the root class is used in the case // of column aggregation inheritance (single table inheritance). $class = $record->getTable()->getComponentName(); $thisTable = $record->getTable(); $table = $thisTable; if ($thisTable->getOption('inheritanceMap')) { // Move up the hierarchy until we find the "subclasses" option. This option // MUST be set on the root class of the user's hierarchy that uses STI. while (!($subclasses = $table->getOption('subclasses'))) { $class = get_parent_class($class); $reflectionClass = new ReflectionClass($class); if ($reflectionClass->isAbstract()) { continue; } if ($class == 'Doctrine_Record') { throw new Doctrine_Node_Exception("No subclasses specified. You are " . "using Single Table Inheritance with NestedSet but you have " . "not specified the subclasses correctly. Make sure you use " . "setSubclasses() in the root class of your hierarchy."); } $table = $table->getConnection()->getTable($class); } } if ($thisTable !== $table) { $this->_tree = $table->getTree(); } else { $this->_tree = $thisTable->getTree(); } }
/** * Refreshs the position of the object * * @param Doctrine_Record $object */ private function refreshPosition(Doctrine_Record $object) { $identifiers = $object->getTable()->getIdentifierColumnNames(); $query = $object->getTable()->createQuery()->select($this->_options['name']); foreach ($identifiers as $identifier) { $query->andWhere($identifier . ' = ?', $object->get($identifier)); } $position = $query->fetchOne(array(), Doctrine::HYDRATE_ARRAY); $object->set($this->_options['name'], $position['position'], false); }
public function setUp() { parent::setUp(); $this->setupTableForRecord('Robo47_Log_Writer_Doctrine_Test_Log'); $this->setupTableForRecord('Robo47_Log_Writer_Doctrine_Test_Log2'); $this->_model = new Robo47_Log_Writer_Doctrine_Test_Log(); $this->_table = $this->_model->getTable(); $this->_model2 = new Robo47_Log_Writer_Doctrine_Test_Log2(); $this->_table2 = $this->_model2->getTable(); $this->_writer = new Robo47_Log_Writer_DoctrineTable($this->_table, array()); }
public function fetchRelatedFor(Doctrine_Record $record) { $id = $record->getIncremented(); $q = new Doctrine_RawSql(); $assocTable = $this->getAssociationFactory()->getTableName(); $tableName = $record->getTable()->getTableName(); $identifier = $record->getTable()->getIdentifier(); $sub = 'SELECT ' . $this->getForeign() . ' FROM ' . $assocTable . ' WHERE ' . $this->getLocal() . ' = ?'; $sub2 = 'SELECT ' . $this->getLocal() . ' FROM ' . $assocTable . ' WHERE ' . $this->getForeign() . ' = ?'; $q->select('{' . $tableName . '.*}, {' . $assocTable . '.*}')->from($tableName . ' INNER JOIN ' . $assocTable . ' ON ' . $tableName . '.' . $identifier . ' = ' . $assocTable . '.' . $this->getLocal() . ' OR ' . $tableName . '.' . $identifier . ' = ' . $assocTable . '.' . $this->getForeign())->where($tableName . '.' . $identifier . ' IN (' . $sub . ') OR ' . $tableName . '.' . $identifier . ' IN (' . $sub2 . ')'); $q->addComponent($tableName, $record->getTable()->getComponentName()); $q->addComponent($assocTable, $record->getTable()->getComponentName() . '.' . $this->getAssociationFactory()->getComponentName()); return $q->execute(array($id, $id)); }
/** * fetchRelatedFor * * fetches a component related to given record * * @param Doctrine_Record $record * @return Doctrine_Record|Doctrine_Collection */ public function fetchRelatedFor(Doctrine_Record $record) { $id = array(); $localTable = $record->getTable(); foreach ((array) $this->definition['local'] as $local) { $value = $record->get($localTable->getFieldName($local)); if (isset($value)) { $id[] = $value; } } if ($this->isOneToOne()) { if (!$record->exists() || empty($id) || !$this->definition['table']->getAttribute(Doctrine::ATTR_LOAD_REFERENCES)) { $related = $this->getTable()->create(); } else { $dql = 'FROM ' . $this->getTable()->getComponentName() . ' WHERE ' . $this->getCondition(); $coll = $this->getTable()->getConnection()->query($dql, $id); $related = $coll[0]; } $related->set($related->getTable()->getFieldName($this->definition['foreign']), $record, false); } else { if (!$record->exists() || empty($id) || !$this->definition['table']->getAttribute(Doctrine::ATTR_LOAD_REFERENCES)) { $related = Doctrine_Collection::create($this->getTable()); } else { $query = $this->getRelationDql(1); $related = $this->getTable()->getConnection()->query($query, $id); } $related->setReference($record, $this); } return $related; }
/** * Automatic 'disabled' field handling * @param Doctrine_Record $record * @param string $field * @throws AppKitDoctrineUtilException */ public static function toggleRecordValue(Doctrine_Record &$record, $field = null) { // Try to autodetect the fieldname if ($field === null) { foreach ($record->getTable()->getColumns() as $name => $info) { if (preg_match('@_disabled$@', $name) && in_array($info['type'], array('boolean', 'integer')) == true) { $field = $name; } } } if ($field && $record->getTable()->hasColumn($field)) { $record->{$field} = !$record->{$field}; } else { throw new AppKitDoctrineUtilException("Field does not exist on the record (tableobject) "); } }
/** * fetchRelatedFor * * fetches a component related to given record * * @param Doctrine_Record $record * @return Doctrine_Record|Doctrine_Collection */ public function fetchRelatedFor(Doctrine_Record $record) { $localFieldName = $record->getTable()->getFieldName($this->definition['local']); $id = $record->get($localFieldName); if (is_null($id) || ! $this->definition['table']->getAttribute(Doctrine_Core::ATTR_LOAD_REFERENCES)) { $related = $this->getTable()->create(); // Ticket #1131 Patch. if ( ! is_null($id)) { $related->assignIdentifier($id); $related->state(Doctrine_Record::STATE_PROXY); } } else { $dql = 'FROM ' . $this->getTable()->getComponentName() . ' WHERE ' . $this->getCondition() . $this->getOrderBy(null, false); $related = $this->getTable() ->getConnection() ->query($dql, array($id)) ->getFirst(); if ( ! $related || empty($related)) { $related = $this->getTable()->create(); } } $record->set($localFieldName, $id, false); return $related; }
public static function getFor(Doctrine_Record $object) { $tableName = $object->getTable()->getTableName(); $componentName = $object->getTable()->getComponentName(); $q = Doctrine_Query::create()->select('c.message, c.parent, c.created_at, c.updated_at, c.created_by, c.updated_by, p.*, v.*,u.*')->from('Comment' . $componentName . ' c')->leftJoin('c.CreatedBy p')->leftJoin('p.User u')->leftJoin('c.VoteComment v')->where('c.' . $tableName . '_id = ?', $object->getId()); $treeObject = Doctrine::getTable('Comment' . $componentName)->getTree(); $treeObject->setBaseQuery($q); $comments = array(); $rootComment = $treeObject->fetchRoots()->getFirst(); if ($rootComment) { foreach ($treeObject->fetchTree(array('root_id' => $rootComment->root_id)) as $comment) { $comments[] = $comment; } } array_shift($comments); return $comments; }
/** * cleanData * this method does several things to records internal data * * 1. It unserializes array and object typed columns * 2. Uncompresses gzip typed columns * 3. Gets the appropriate enum values for enum typed columns * 4. Initializes special null object pointer for null values (for fast column existence checking purposes) * * * example: * * $data = array("name" => "John", "lastname" => null, "id" => 1, "unknown" => "unknown"); * $data after operation: * $data = array("name" => "John", "lastname" => Object(Doctrine_Null)); * * here column 'id' is removed since its auto-incremented primary key (read-only) * * @throws Doctrine_Record_Exception if unserialization of array/object typed column fails or * if uncompression of gzip typed column fails * * @param array $data data array to be cleaned * @return integer */ public function cleanData($data) { foreach ($this->_record->getTable()->getColumnNames() as $name) { if (!isset($data[$name])) { $data[$name] = self::$_null; } } return $data; }
/** * Validates a given record and saves possible errors in Doctrine_Validator::$stack * * @param Doctrine_Record $record * @return void */ public function validateRecord(Doctrine_Record $record) { $table = $record->getTable(); // if record is transient all fields will be validated // if record is persistent only the modified fields will be validated $fields = $record->exists() ? $record->getModified() : $record->getData(); foreach ($fields as $fieldName => $value) { $table->validateField($fieldName, $value, $record); } }
/** * contructor, creates node with reference to record and any options * * @param object $record instance of Doctrine_Record * @param array $options options */ public function __construct(Doctrine_Record $record, $options) { $this->record = $record; $this->options = $options; // Make sure that the tree object of the root component is used in the case // of column aggregation inheritance. $class = $record->getTable()->getComponentName(); $table = $record->getTable(); if ($table->getOption('inheritanceMap')) { $subclasses = $table->getOption('subclasses'); while (in_array($class, $subclasses)) { $class = get_parent_class($class); } } if ($class != $table->getComponentName()) { $this->_tree = $table->getConnection()->getTable($class)->getTree(); } else { $this->_tree = $table->getTree(); } }
public function initRelated(Doctrine_Record $record, $name) { if (!isset($this->_initializedRelations[$record->getOid()][$name])) { $relation = $record->getTable()->getRelation($name); $coll = new Doctrine_Collection($relation->getTable()->getComponentName()); $coll->setReference($record, $relation); $record[$name] = $coll; $this->_initializedRelations[$record->getOid()][$name] = true; } return true; }
/** * Creates root node from given record or from a new record. * * Note: When using a tree with multiple root nodes (hasManyRoots), you MUST pass in a * record to use as the root. This can either be a new/transient record that already has * the root id column set to some numeric value OR a persistent record. In the latter case * the records id will be assigned to the root id. You must use numeric columns for the id * and root id columns. * * @param object $record instance of Doctrine_Record */ public function createRoot(Doctrine_Record $record = null) { if ($this->getAttribute('hasManyRoots')) { if (!$record || !$record->exists() && $record->getNode()->getRootValue() <= 0 || $record->getTable()->isIdentifierComposite()) { throw new Doctrine_Tree_Exception("Node must have a root id set or must " . " be persistent and have a single-valued numeric primary key in order to" . " be created as a root node. Automatic assignment of a root id on" . " transient/new records is no longer supported."); } if ($record->exists() && $record->getNode()->getRootValue() <= 0) { // Default: root_id = id $identifier = $record->getTable()->getIdentifier(); $record->getNode()->setRootValue($record->get($identifier)); } } if (!$record) { $record = $this->table->create(); } $record->set('lft', '1'); $record->set('rgt', '2'); $record->set('level', 0); $record->save(); return $record; }
/** * Dumps a record. * * This method returns an html representation of a given * record, containing keys, state and data. * * @param Doctrine_Record $record * @return string */ public static function getRecordAsString(Doctrine_Record $record) { $r[] = '<pre>'; $r[] = 'Component : ' . $record->getTable()->getComponentName(); $r[] = 'ID : ' . Doctrine::dump($record->identifier()); $r[] = 'References : ' . count($record->getReferences()); $r[] = 'State : ' . Doctrine_Lib::getRecordStateAsString($record->state()); $r[] = 'OID : ' . $record->getOID(); $r[] = 'data : ' . Doctrine::dump($record->getData(), false); $r[] = '</pre>'; return implode("\n", $r) . "<br />"; }
/** * @param Doctrine_Record|Doctrine_Collection|Array $data * @param null|Doctrine_Table $table * @return Kebab_Validate_Doctrine_Table */ protected function _setTable($data, $table = null) { if (is_null($table) && $data instanceof Doctrine_Record) { $this->_table = $data->getTable(); } if (!is_null($table) && $table instanceof Doctrine_Table) { $this->_table = $table; } if (is_string($table) && !$table instanceof Doctrine_Table) { $this->_table = Doctrine_Core::getTable($table); } return $this; }
/** * buildIntegrityRelationQuery * * @param Doctrine_Record $record * @return array The result */ public function buildIntegrityRelationQuery(Doctrine_Record $record) { $q = $record->getTable()->createQuery(); $aliases = array(); $indexes = array(); $root = $record->getTable()->getComponentName(); $rootAlias = strtolower(substr($root, 0, 1)); $aliases[$rootAlias] = $root; foreach ((array) $record->getTable()->getIdentifier() as $id) { $field = $rootAlias . '.' . $id; $cond[] = $field . ' = ?'; $fields[] = $field; $params = $record->get($id); } $fields = implode(', ', $fields); $components[] = $root; $this->buildIntegrityRelations($record->getTable(), $aliases, $fields, $indexes, $components); $q->select($fields)->from($root . ' ' . $rootAlias); foreach ($aliases as $alias => $name) { $q->leftJoin($rootAlias . '.' . $name . ' ' . $alias); } $q->where(implode(' AND ', $cond)); return $q->execute(array($params)); }
/** * fetchRelatedFor * * fetches a component related to given record * * @param Doctrine_Record $record * @return Doctrine_Record|Doctrine_Collection */ public function fetchRelatedFor(Doctrine_Record $record) { $localFieldName = $record->getTable()->getFieldName($this->definition['local']); $id = $record->get($localFieldName); if (is_null($id) || !$this->definition['table']->getAttribute(Doctrine::ATTR_LOAD_REFERENCES)) { $related = $this->getTable()->create(); } else { $dql = 'FROM ' . $this->getTable()->getComponentName() . ' WHERE ' . $this->getCondition(); $related = $this->getTable()->getConnection()->query($dql, array($id))->getFirst(); if (!$related || empty($related)) { $related = $this->getTable()->create(); } } $record->set($localFieldName, $related, false); return $related; }
/** * filterSet * defines an implementation for filtering the set() method of Doctrine_Record * * @param mixed $name name of the property or related component */ public function filterSet(Doctrine_Record $record, $name, $value) { if (in_array($name, array_keys($this->_options['fields']))) { $template = $record->getTable()->getTemplate('Localizable'); $unit = $this->_options['fields'][$name]; if (isset($this->_localizables[$name])) { $this->_localizables[$name]->setValue((string) $value, $unit); $localizable = $this->_localizables[$name]; } else { $localizable = new LocalizableUnit($value, $unit, $this->_options['conversions']); $this->_localizables[$name] = $localizable; } $field = $this->_options['columns'][$name]; $record->{$field} = $value; return $record; } throw new Doctrine_Record_UnknownPropertyException(sprintf('Unknown record property / related component "%s" on unit filter "%s"', $name, get_class($record))); }
/** * Get distance between this record and another * * @param string $Doctrine_Record * @param string $kilometers * @return integer */ public function getDistance(Doctrine_Record $record, $kilometers = false) { $query = $this->getDistanceQuery($kilometers); $conditions = array(); $values = array(); foreach ((array) $record->getTable()->getIdentifier() as $id) { $conditions[] = $query->getRootAlias() . '.' . $id . ' = ?'; $values[] = $record->get($id); } $where = implode(' AND ', $conditions); $query->addWhere($where, $values); $query->limit(1); $result = $query->execute()->getFirst(); if (isset($result['kilometers']) && $result['miles']) { return $kilometers ? $result->get('kilometers') : $result->get('miles'); } else { return 0; } }
public function fetchRelatedValues(Doctrine_Record $record, $property) { if ($record->getTable()->isIdentifier($property)) { $value = $record->{$property}; return $value ? array($value) : array(); } $values = array(); $skipDirectPropertyGet = false; // Record available translations of property, if available if ($record->hasRelation('Translation')) { if (!is_null($this->cacheUriCulture) && $this->hasTranslation($record, $this->cacheUriCulture)) { $translations = array($record->Translation[$this->cacheUriCulture]); $skipDirectPropertyGet = true; } else { $translations = $record->Translation; } foreach ($translations as $translation) { if (isset($translation[$property]) && $translation[$property]) { $values[] = $translation[$property]; } } } // Standard property get if (false === $skipDirectPropertyGet) { try { // circumvents a silly Doctrine behavior which may alter the record instance reference // when trying to access some of its properties, so we copy it instead to be safe $copy = $record->copy(false); if ($value = (string) $copy->{$property}) { $values[] = $value; } $copy->free(true); } catch (Exception $e) { $values[] = '*'; } } return array_unique($values); }
/** * @param Doctrine_Record $record * @param string $key * @param mixed $value * @param string $args * @return boolean */ public function validate(Doctrine_Record $record, $key, $value, $args) { $table = $record->getTable(); $pks = $table->getIdentifier(); if (is_array($pks)) { $pks = join(',', $pks); } $sql = 'SELECT ' . $pks . ' FROM ' . $table->getTableName() . ' WHERE ' . $key . ' = ?'; $values = array(); $values[] = $value; // If the record is not new we need to add primary key checks because its ok if the // unique value already exists in the database IF the record in the database is the same // as the one that is validated here. $state = $record->getState(); if (!($state == Doctrine_Record::STATE_TDIRTY || $state == Doctrine_Record::STATE_TCLEAN)) { foreach ($table->getPrimaryKeys() as $pk) { $sql .= " AND {$pk} != ?"; $values[] = $record->{$pk}; } } $stmt = $table->getConnection()->getDbh()->prepare($sql); $stmt->execute($values); return !is_array($stmt->fetch()); }
/** * setAccess * defines unified access setting strategy for users and groups * * Sets an access rule for given user/group. * * Defines whether given user/group is allowed or denied to access given resource * with given permission. * * @param Koch_User|Koch_Group $record * @param string $resource name of the resource * @param string $permission name of the permission * @param boolean $allow defines whether this user has access to * given resource with given permission or not */ public function setAccess(Doctrine_Record $record, $resource = null, $permission = null, $allow) { if ($record instanceof Koch_User) { $accessClass = 'Koch_Acl_UserAccess'; $linkField = 'user_id'; } elseif ($record instanceof Koch_Group) { $accessClass = 'Koch_Acl_GroupAccess'; $linkField = 'group_id'; } else { throw new Koch_Acl_Exception('Unknown object given.'); } if ($permission === null) { $permission = $this->getOption('global_permission'); } if ($resource === null) { $resource = $this->getOption('global_resource'); } $global_access = $permission === $this->getOption('global_permission') || $resource === $this->getOption('global_resource'); $conn = $record->getTable()->getConnection(); $access = Doctrine_Query::create()->from($accessClass . ' a')->where('a.resource_name = ? AND a.permission_name = ? AND a.' . $linkField . ' = ?')->fetchOne(array($resource, $permission, $record->id), Doctrine::HYDRATE_ARRAY); if ($access == false) { if ($global_access == false) { $link = Doctrine_Query::create()->from('Koch_Acl_ResourcePermission p')->where('p.resource = ? AND p.permission = ?')->fetchOne(array($resource, $permission), Doctrine::HYDRATE_ARRAY); if (!$link) { throw new Koch_Acl_Exception('Resource ' . $resource . ' does not have link to permission ' . $permission); } } $access = new $accessClass(); $access->resource_name = $resource; $access->permission_name = $permission; $access->{$linkField} = $record; } $access->allow = $allow; $access->save(); return $access; }
/** * Gets the identifier that identifies the owner of the lock on the given * record. * * @param Doctrine_Record $lockedRecord The record. * @return mixed The unique user identifier that identifies the owner of the lock. */ public function getLockOwner($lockedRecord) { $objectType = $lockedRecord->getTable()->getComponentName(); $key = $lockedRecord->getTable()->getIdentifier(); return $this->_getLockingUserIdent($objectType, $key); }
/** * Get the max version number for a given Doctrine_Record * * @param Doctrine_Record $record * @return Integer $versionnumber */ public function getMaxVersion(Doctrine_Record $record) { $className = $this->_options['className']; $select = 'MAX(' . $className . '.' . $this->_options['version']['name'] . ') max_version'; foreach ((array) $this->_options['table']->getIdentifier() as $id) { $conditions[] = $className . '.' . $id . ' = ?'; $values[] = $record->get($id); } $q = Doctrine_Query::create($record->getTable()->getConnection())->select($select)->from($className)->where(implode(' AND ', $conditions)); $result = $q->execute($values, Doctrine_Core::HYDRATE_ARRAY); return isset($result[0]['max_version']) ? $result[0]['max_version'] : 0; }
/** * enforces the "can't modify the past" rules * * @param $record * @return null */ private function enforceTemporalModConstraints(Doctrine_Record &$record) { $today = date($this->date_format); $modified_table = $record->getTable()->getComponentName(); $modified_from = $record->getModified(true); $modified_to = $record->getModified(); $problem = false; if (@$modified_from[$this->_options['eff_date']] && $modified_from[$this->_options['eff_date']] < $today) { $problem = 'from effective'; $date = $modified_from[$this->_options['eff_date']]; } elseif (@$modified_from[$this->_options['exp_date']] && $modified_from[$this->_options['exp_date']] < $today) { $problem = 'from expiration'; $date = $modified_from[$this->_options['exp_date']]; } elseif (!is_null($record[$this->_options['exp_date']]) && $record[$this->_options['exp_date']] < $today) { $problem = 'expiration'; $date = $record[$this->_options['exp_date']]; } if ($problem) { throw new Doctrine_Temporal_PastModificationException("Won't modify past {$modified_table} {$problem} date: " . $date); } // now, check for modification of a current record OTHER THAN SETTING EXP_DATE if ($record[$this->_options['eff_date']] < $today) { foreach ($modified_to as $k => &$v) { // let the exp_date change, since it doesn't have any effect on the past if ($k == $this->_options['exp_date']) { continue; } // make sure the value has actually changed (sometimes re-setting the same value will give a false positive) if ($v == $record[$k]) { continue; } // some other modified field was found, which is not allowed (since it would affect the past) throw new Doctrine_Temporal_PastModificationException("Won't modify current record (except terminating it). Requested to save {$k} = {$v} as of {$today}."); } } }
/** * addDelete * adds record into pending delete list * * @param Doctrine_Record $record a record to be added * @return void */ public function addDelete(Doctrine_Record $record) { $name = $record->getTable()->getComponentName(); $this->delete[$name][] = $record; }
/** * isRelation * * Check if a fieldName on a Doctrine_Record is a relation, if it is we return that relationData * * @param string $Doctrine_Record * @param string $fieldName * @return void */ public function isRelation(Doctrine_Record $record, $fieldName) { $relations = $record->getTable()->getRelations(); foreach ($relations as $relation) { $relationData = $relation->toArray(); if ($relationData['local'] === $fieldName) { return $relationData; } } return false; }
/** * Get the unsaved object for a specified row key and validate that it is the valid object class * for the passed record and relation name * * @param string $rowKey * @param Doctrine_Record $record * @param string $relationName * @param string $referringRowKey * @return Doctrine_Record * @throws Doctrine_Data_Exception */ protected function _getImportedObject($rowKey, Doctrine_Record $record, $relationName, $referringRowKey) { $relation = $record->getTable()->getRelation($relationName); $rowKey = $this->_getRowKeyPrefix($relation->getTable()) . $rowKey; if ( ! isset($this->_importedObjects[$rowKey])) { throw new Doctrine_Data_Exception( sprintf('Invalid row key specified: %s, referred to in %s', $rowKey, $referringRowKey) ); } $relatedRowKeyObject = $this->_importedObjects[$rowKey]; $relationClass = $relation->getClass(); if ( ! $relatedRowKeyObject instanceof $relationClass) { throw new Doctrine_Data_Exception(sprintf( 'Class referred to in "%s" is expected to be "%s" and "%s" was given', $referringRowKey, $relation->getClass(), get_class($relatedRowKeyObject) )); } return $relatedRowKeyObject; }
protected function _assignIdentifier(Doctrine_Record $record) { $table = $record->getTable(); $identifier = $table->getIdentifier(); $seq = $table->sequenceName; if (empty($seq) && !is_array($identifier) && $table->getIdentifierType() != Doctrine_Core::IDENTIFIER_NATURAL) { $id = false; if ($record->{$identifier} == null) { if (($driver = strtolower($this->conn->getDriverName())) == 'pgsql') { $seq = $table->getTableName() . '_' . $table->getColumnName($identifier); } elseif ($driver == 'oracle' || $driver == 'mssql') { $seq = $table->getTableName(); } $id = $this->conn->sequence->lastInsertId($seq); } else { $id = $record->{$identifier}; } if (!$id) { throw new Doctrine_Connection_Exception("Couldn't get last insert identifier."); } $record->assignIdentifier($id); } else { $record->assignIdentifier(true); } }