From 56407f785aa112833d6f3dad30ee960b201deee3 Mon Sep 17 00:00:00 2001 From: romanb Date: Sun, 3 Feb 2008 21:29:57 +0000 Subject: [PATCH] Merged r3518:r3700 from branch to trunk. Branch to be deleted, soon. Development continues in trunk. --- lib/Doctrine/ClassMetadata.php | 1551 +++++++++++++++++ lib/Doctrine/ClassMetadata/CodeDriver.php | 18 + lib/Doctrine/ClassMetadata/Exception.php | 3 + lib/Doctrine/ClassMetadata/Factory.php | 276 +++ lib/Doctrine/ClassMetadata/YamlDriver.php | 16 + lib/Doctrine/Column.php | 158 -- lib/Doctrine/Configurable.php | 12 +- lib/Doctrine/Connection.php | 215 ++- lib/Doctrine/Export.php | 53 +- lib/Doctrine/Hydrator.php | 11 +- lib/Doctrine/Hydrator/ArrayDriver.php | 40 +- lib/Doctrine/Hydrator/RecordDriver.php | 36 +- lib/Doctrine/Manager.php | 29 + lib/Doctrine/Mapper/Abstract.php | 159 +- lib/Doctrine/Mapper/Joined.php | 86 +- lib/Doctrine/Mapper/SingleTable.php | 2 +- lib/Doctrine/Node/NestedSet.php | 6 +- lib/Doctrine/Query.php | 2 +- lib/Doctrine/Query/Abstract.php | 40 +- lib/Doctrine/Query/Check.php | 2 +- lib/Doctrine/Query/Where.php | 2 +- lib/Doctrine/RawSql.php | 5 +- lib/Doctrine/Record.php | 134 +- lib/Doctrine/Record/Abstract.php | 116 +- lib/Doctrine/Record/Filter.php | 2 +- lib/Doctrine/Record/Generator.php | 4 +- lib/Doctrine/Relation.php | 7 +- lib/Doctrine/Relation/Association.php | 14 +- lib/Doctrine/Relation/Parser.php | 74 +- lib/Doctrine/Table/Factory.php | 16 +- lib/Doctrine/Template.php | 2 +- lib/Doctrine/Tree.php | 4 +- lib/Doctrine/Tree/NestedSet.php | 2 +- lib/Doctrine/Validator.php | 19 +- models/Account.php | 6 +- models/Address.php | 8 +- models/Album.php | 13 +- models/App.php | 16 +- models/App_Category.php | 12 +- models/App_User.php | 20 +- models/Assignment.php | 6 +- models/Auth.php | 11 +- models/Author.php | 11 +- models/BadlyNamed__Class.php | 3 +- models/BarRecord.php | 11 +- models/BaseSymfonyRecord.php | 8 +- models/Blog.php | 21 +- models/BlogTag.php | 19 +- models/BoardWithPosition.php | 10 +- models/Book.php | 13 +- models/Bookmark.php | 6 +- models/BookmarkUser.php | 9 +- models/BooleanTest.php | 6 +- models/CPK_Association.php | 6 +- models/CPK_Test.php | 8 +- models/CPK_Test2.php | 8 +- models/CascadeDeleteRelatedTest.php | 13 +- models/CascadeDeleteRelatedTest2.php | 11 +- models/CascadeDeleteTest.php | 9 +- models/CategoryNestedSet.php | 17 +- models/CategoryWithPosition.php | 10 +- models/CheckConstraintTest.php | 8 +- models/ClientModel.php | 57 +- models/ColumnAliasTest.php | 15 +- models/ConcreteEmail.php | 4 +- models/ConcreteGroup.php | 4 +- models/ConcreteGroupUser.php | 4 +- models/ConcreteInheritanceTestParent.php | 10 +- models/ConcreteUser.php | 4 +- models/CoverageCodeN.php | 14 +- models/CustomPK.php | 6 +- models/CustomSequenceRecord.php | 6 +- models/Data_File.php | 10 +- models/DateTest.php | 4 +- models/Description.php | 6 +- models/Element.php | 12 +- models/Email.php | 4 +- models/Entity.php | 37 +- models/EntityAddress.php | 6 +- models/EntityReference.php | 7 +- models/EnumTest.php | 12 +- models/EnumTest2.php | 6 +- models/EnumTest3.php | 4 +- models/Error.php | 12 +- models/EventListenerChainTest.php | 6 +- models/EventListenerTest.php | 9 +- models/FieldNameTest.php | 12 +- models/File_Owner.php | 8 +- models/FilterTest.php | 8 +- models/FilterTest2.php | 6 +- models/FooBarRecord.php | 6 +- models/FooForeignlyOwned.php | 6 +- models/FooForeignlyOwnedWithPK.php | 8 +- models/FooLocallyOwned.php | 4 +- models/FooRecord.php | 29 +- models/FooReferenceRecord.php | 9 +- models/ForeignKeyTest.php | 18 +- models/ForeignKeyTest2.php | 9 +- models/Forum_Board.php | 14 +- models/Forum_Category.php | 18 +- models/Forum_Entry.php | 20 +- models/Forum_Thread.php | 14 +- models/Group.php | 12 +- models/GroupUser.php | 16 - models/Groupuser.php | 12 + models/GzipTest.php | 4 +- models/I18nTest.php | 11 +- models/InheritanceDeal.php | 14 +- models/InheritanceDealUser.php | 39 +- models/InheritanceUser.php | 14 +- models/JC1.php | 6 +- models/JC2.php | 6 +- models/JC3.php | 6 +- models/LiabilityCodeN.php | 14 +- models/Location.php | 12 +- models/LocationI18n.php | 14 +- models/Log_Entry.php | 10 +- models/Log_Status.php | 4 +- models/M2MTest.php | 18 +- models/M2MTest2.php | 10 +- models/MigrationTest.php | 4 +- models/MyUserOneThing.php | 6 +- models/MysqlGroup.php | 7 +- models/MysqlIndexTestRecord.php | 14 +- models/MysqlTestRecord.php | 8 +- models/MysqlUser.php | 7 +- models/NestReference.php | 6 +- models/NestTest.php | 13 +- models/NestedSetTest_SingleRootNode.php | 6 +- models/NotNullTest.php | 6 +- models/ORM_AccessControl.php | 12 +- models/ORM_AccessControlsGroups.php | 6 +- models/ORM_AccessGroup.php | 11 +- models/Package.php | 10 +- models/Page.php | 12 +- models/Phonenumber.php | 16 +- models/Photo.php | 8 +- models/Phototag.php | 6 +- models/PluginSymfonyRecordTable.php | 2 +- models/Policy.php | 13 +- models/PolicyAsset.php | 14 +- models/PolicyCodeN.php | 14 +- models/PolicyN.php | 15 +- models/QueryTest_Board.php | 22 +- models/QueryTest_Category.php | 24 +- models/QueryTest_Entry.php | 15 +- models/QueryTest_Item.php | 6 +- models/QueryTest_Rank.php | 16 +- models/QueryTest_User.php | 17 +- models/QueryTest_UserRank.php | 6 +- models/RTC4.php | 10 +- models/RateN.php | 26 +- models/Rec1.php | 10 +- models/Rec2.php | 13 +- models/RecordFilterTest.php | 7 +- models/RecordHookTest.php | 20 +- models/Record_City.php | 14 +- models/Record_Country.php | 8 +- models/Record_District.php | 4 +- models/RelationTest.php | 12 +- models/Resource.php | 10 +- models/ResourceReference.php | 6 +- models/ResourceType.php | 8 +- models/Role.php | 10 +- models/SearchTest.php | 14 +- models/SelfRefTest.php | 11 +- models/SerializeTest.php | 30 +- models/SoftDeleteTest.php | 12 +- models/Song.php | 13 +- models/Tag.php | 8 +- models/Task.php | 12 +- models/TestMovie.php | 16 +- models/TestMovieUserBookmark.php | 6 +- models/TestMovieUserVote.php | 8 +- models/TestRecord.php | 4 +- models/TestUser.php | 12 +- models/TreeLeaf.php | 16 +- models/User.php | 26 +- models/ValidatorTest.php | 20 +- models/ValidatorTest_AddressModel.php | 20 +- models/ValidatorTest_ClientModel.php | 12 +- models/ValidatorTest_ClientToAddressModel.php | 13 +- models/ValidatorTest_DateModel.php | 6 +- models/ValidatorTest_FootballPlayer.php | 8 +- models/ValidatorTest_Person.php | 11 +- models/VersioningTest.php | 11 +- models/ZeroValueTest.php | 23 +- models/export/Cms_Category.php | 25 +- models/export/Cms_CategoryLanguages.php | 27 +- models/gnatEmail.php | 4 +- models/gnatUser.php | 16 +- models/mmrGroupUser_B.php | 6 +- models/mmrGroupUser_C.php | 6 +- models/mmrGroup_C.php | 11 +- tests/AuditLogTestCase.php | 2 +- tests/Collection/SnapshotTestCase.php | 2 +- .../ColumnAggregationInheritanceTestCase.php | 24 +- tests/ConnectionTestCase.php | 11 +- tests/DoctrineTest/Doctrine_UnitTestCase.php | 67 +- tests/Hydrate/FetchModeTestCase.php | 4 + tests/HydrateTestCase.php | 4 +- tests/Import/MssqlTestCase.php | 2 +- tests/Inheritance/JoinedTestCase.php | 92 +- tests/Inheritance/SingleTableTestCase.php | 68 +- tests/Inheritance/TablePerClassTestCase.php | 44 +- tests/Metadata/FactoryTestCase.php | 249 +++ tests/NestedSet/SingleRootTestCase.php | 8 +- tests/Query/AggregateValueTestCase.php | 8 +- tests/Query/DeleteTestCase.php | 16 +- tests/Query/JoinCondition2TestCase.php | 42 +- tests/Query/JoinTestCase.php | 2 +- .../Query/MultipleAggregateValueTestCase.php | 11 +- tests/Query/SelectTestCase.php | 70 +- tests/Query/WhereTestCase.php | 2 +- tests/QueryTestCase.php | 1 + tests/RawSqlTestCase.php | 8 +- tests/Record/FilterTestCase.php | 17 +- tests/RecordTestCase.php | 26 +- tests/Relation/OneToManyTestCase.php | 6 +- tests/Relation/ParserTestCase.php | 34 +- tests/RelationTestCase.php | 4 +- tests/TableTestCase.php | 8 +- tests/Ticket/428TestCase.php | 8 +- tests/Ticket/438TestCase.php | 49 +- tests/Ticket/480TestCase.php | 8 +- tests/Ticket/626BTestCase.php | 67 +- tests/Ticket/626CTestCase.php | 16 +- tests/Ticket/626DTestCase.php | 8 +- tests/Ticket/638TestCase.php | 44 +- tests/Ticket/642TestCase.php | 6 +- tests/Ticket/673TestCase.php | 10 +- tests/Ticket/697TestCase.php | 29 +- tests/Ticket/741TestCase.php | 26 +- tests/Ticket/NjeroTestCase.php | 1 + tests/run.php | 28 +- 235 files changed, 3943 insertions(+), 2161 deletions(-) create mode 100644 lib/Doctrine/ClassMetadata.php create mode 100644 lib/Doctrine/ClassMetadata/CodeDriver.php create mode 100644 lib/Doctrine/ClassMetadata/Exception.php create mode 100644 lib/Doctrine/ClassMetadata/Factory.php create mode 100644 lib/Doctrine/ClassMetadata/YamlDriver.php delete mode 100644 lib/Doctrine/Column.php delete mode 100644 models/GroupUser.php create mode 100644 models/Groupuser.php create mode 100644 tests/Metadata/FactoryTestCase.php diff --git a/lib/Doctrine/ClassMetadata.php b/lib/Doctrine/ClassMetadata.php new file mode 100644 index 000000000..84fa14331 --- /dev/null +++ b/lib/Doctrine/ClassMetadata.php @@ -0,0 +1,1551 @@ + + */ +class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializable +{ + /** + * The name of the domain class that is mapped to the database with this metadata. + * + * @var string + */ + protected $_domainClassName; + + /** + * + * @var Doctrine_Connection + */ + protected $_conn; + + /** + * The names of the parent classes. + */ + protected $_parentClasses = array(); + + /** + * The field names of all fields that are part of the identifier/primary key + * of the described class. + * + * @var array + */ + protected $_identifier = array(); + + /** + * The identifier type of the class. + * + * @see Doctrine_Identifier constants + * @var integer + */ + protected $_identifierType; + + /** + * The inheritance mapping type used by the class. + * + * @var integer + */ + protected $_inheritanceType = Doctrine::INHERITANCETYPE_TABLE_PER_CLASS; + + /** + * The name of the column that acts as a discriminator to identify the type of an + * object. Used in Single Table Inheritance and Class Table Inheritance. + * + * @var string + */ + protected $_discriminatorColumn; + + /** + * The discriminator map contains the mapping of discriminator values (keys) + * to class names (values). + * + * @var array + */ + protected $_discriminatorMap; + + /** + * An array containing all templates attached to the class. + * + * @see Doctrine_Template + * @var array $_templates + */ + protected $_templates = array(); + + /** + * An array containing all generators attached to this class. + * + * @see Doctrine_Record_Generator + * @var array $_generators + */ + protected $_generators = array(); + + /** + * An array containing all filters attached to this class. + * + * @see Doctrine_Record_Filter + * @var array $_filters + */ + protected $_filters = array(); + + /** + * An array of column definitions, + * keys are column names and values are column definitions + * + * the definition array has atleast the following values: + * + * -- type the column type, eg. 'integer' + * -- length the column length, eg. 11 + * + * additional keys: + * -- notnull whether or not the column is marked as notnull + * -- values enum values + * -- notblank notblank validator + notnull constraint + * ... many more + * + * @var array $columns + */ + protected $_columns = array(); + + /** + * An array of field names. used to look up field names from column names. + * Keys are column names and values are field names. + * + * @var array + */ + protected $_fieldNames = array(); + + /** + * An array of column names. Keys are field names and values column names. + * Used to look up column names from field names. + * This is the reverse lookup map of $_fieldNames. + * + * @var array + */ + protected $_columnNames = array(); + + /** + * @todo Implementation. + */ + protected $_readOnlyFieldNames = array(); + + /** + * Tree object associated with the class. + * + * @var Doctrine_Tree + */ + protected $_tree; + + /** + * Cached column count, Doctrine_Record uses this column count in when + * determining its state. + * + * @var integer + */ + protected $columnCount; + + /** + * Whether or not this class has default values. + * + * @var boolean + */ + protected $_hasDefaultValues; + + /** + * Relation parser object. Manages the relations for the class. + * + * @var Doctrine_Relation_Parser $_parser + */ + protected $_parser; + + /** + * Contains the mapping of the discriminator column (which discriminator value identifies + * which class). Used in Single & Class Table Inheritance. + */ + protected $_inheritanceMap = array(); + + /** + * Enum value arrays. + */ + protected $_enumMap = array(); + + /** + * @var array $options an array containing all options + * + * -- parents the parent classes of this component + * + * -- treeImpl the tree implementation of this table (if any) + * + * -- treeOptions the tree options + * + * -- queryParts the bound query parts + */ + protected $_options = array( + 'treeImpl' => null, + 'treeOptions' => null, + 'subclasses' => array(), + 'queryParts' => array(), + 'parents' => array() + ); + + /** + * + */ + protected $_inheritanceOptions = array( + 'discriminatorColumn' => null, + 'discriminatorMap' => array(), + 'joinSubclasses' => true + ); + + /** + * Specific options that can be set for the database table the class is mapped to. + * Some of them are dbms specific and they are only used if the table is generated + * by Doctrine (NOT when using Migrations). + * + * -- type table type (mysql example: INNODB) + * + * -- charset character set + * + * -- checks the check constraints of this table, eg. 'price > dicounted_price' + * + * -- collation collation attribute + * + * -- indexes the index definitions of this table + * + * -- sequenceName Some databases need sequences instead of auto incrementation primary keys, + * you can set specific sequence for your table by calling setOption('sequenceName', $seqName) + * where $seqName is the name of the desired sequence + */ + protected $_tableOptions = array( + 'tableName' => null, + 'sequenceName' => null, + 'type' => null, + 'charset' => null, + 'collation' => null, + 'collate' => null, + 'indexes' => array(), + 'checks' => array() + ); + + /** + * Constructs a new metadata instance. + * + * @param string $domainClassName Name of the class the metadata instance is used for. + */ + public function __construct($domainClassName, Doctrine_Connection $conn) + { + $this->_domainClassName = $domainClassName; + $this->_conn = $conn; + $this->_parser = new Doctrine_Relation_Parser($this); + $this->_filters[] = new Doctrine_Record_Filter_Standard(); + $this->setParent($this->_conn); + } + + /** + * + */ + public function getConnection() + { + return $this->_conn; + } + + /** + * getComponentName + * + * @return void + */ + public function getClassName() + { + return $this->_domainClassName; + } + + public function getComponentName() + { + return $this->getClassName(); + } + + /** + * Whether a field is part of the identifier/primary key field(s). + * + * @param string $fieldName The field name + * @return boolean TRUE if the field is part of the table identifier/primary key field(s), + * FALSE otherwise. + */ + public function isIdentifier($fieldName) + { + return ($fieldName === $this->getIdentifier() || + in_array($fieldName, (array) $this->getIdentifier())); + } + + /** + * addIndex + * + * adds an index to this table + * + * @return void + */ + public function addIndex($index, array $definition) + { + $this->_tableOptions['indexes'][$index] = $definition; + } + + /** + * getIndex + * + * @return array|boolean array on success, FALSE on failure + */ + public function getIndex($index) + { + if (isset($this->_tableOptions['indexes'][$index])) { + return $this->_tableOptions['indexes'][$index]; + } + + return false; + } + + /** + * setOption + * sets an option and returns this object in order to + * allow flexible method chaining + * + * @see Doctrine_Table::$_options for available options + * @param string $name the name of the option to set + * @param mixed $value the value of the option + * @return Doctrine_Table this object + */ + public function setOption($name, $value) + { + switch ($name) { + case 'tableName': + case 'index': + case 'sequenceName': + case 'type': + case 'charset': + case 'collation': + case 'collate': + return $this->setTableOption($name, $value); + case 'enumMap': + $this->_enumMap = $value; + return; + case 'inheritanceMap': + $this->_inheritanceMap = $value; + return; + } + $this->_options[$name] = $value; + } + + /** + * + */ + public function setTableOption($name, $value) + { + if ( ! array_key_exists($name, $this->_tableOptions)) { + throw new Doctrine_MetadataClass_Exception("Unknown table option: '$name'."); + } + $this->_tableOptions[$name] = $value; + } + + /** + * + */ + public function getTableOption($name) + { + if ( ! array_key_exists($name, $this->_tableOptions)) { + throw new Doctrine_MetadataClass_Exception("Unknown table option: '$name'."); + } + + return $this->_tableOptions[$name]; + } + + /** + * getOption + * returns the value of given option + * + * @param string $name the name of the option + * @return mixed the value of given option + */ + public function getOption($name) + { + if (isset($this->_options[$name])) { + return $this->_options[$name]; + } else if (isset($this->_tableOptions[$name])) { + return $this->_tableOptions[$name]; + } + return null; + } + + /** + * getOptions + * returns all options of this table and the associated values + * + * @return array all options and their values + */ + public function getOptions() + { + return $this->_options; + } + + /** + * getTableOptions + * returns all table options. + * + * @return array all options and their values + */ + public function getTableOptions() + { + return $this->_tableOptions; + } + + /** + * getColumnName + * + * returns a column name for a field name. + * if the actual name for the alias cannot be found + * this method returns the given alias + * + * @param string $alias column alias + * @return string column name + */ + public function getColumnName($fieldName) + { + if (isset($this->_columnNames[$fieldName])) { + return $this->_columnNames[$fieldName]; + } + + return $fieldName; + } + + /** + * + * + */ + public function getColumnDefinition($columnName) + { + if ( ! isset($this->_columns[$columnName])) { + return false; + } + + return $this->_columns[$columnName]; + } + + /** + * getColumnAlias + * + * returns a column alias for a column name + * if no alias can be found the column name is returned. + * + * @param string $columnName column name + * @return string column alias + */ + public function getFieldName($columnName) + { + if (isset($this->_fieldNames[$columnName])) { + return $this->_fieldNames[$columnName]; + } + + return $columnName; + } + + public function setColumns(array $definitions) + { + foreach ($definitions as $name => $options) { + $this->setColumn($name, $options['type'], $options['length'], $options); + } + } + + public function mapField($name, $type, $length = null, $options = array(), $prepend = false) + { + return $this->setColumn($name, $type, $length, $options, $prepend); + } + + /** + * setColumn + * + * @param string $name + * @param string $type + * @param integer $length + * @param mixed $options + * @param boolean $prepend Whether to prepend or append the new column to the column list. + * By default the column gets appended. + * @throws Doctrine_Table_Exception if trying use wrongly typed parameter + * @return void + */ + public function setColumn($name, $type, $length = null, $options = array(), $prepend = false) + { + if (is_string($options)) { + $options = explode('|', $options); + } + + foreach ($options as $k => $option) { + if (is_numeric($k)) { + if ( ! empty($option)) { + $options[$option] = true; + } + unset($options[$k]); + } + } + + // extract column name & field name + $parts = explode(' as ', $name); + if (count($parts) > 1) { + $fieldName = $parts[1]; + } else { + $fieldName = $parts[0]; + } + $name = strtolower($parts[0]); + + if (isset($this->_columnNames[$fieldName])) { + return; + } + + if ($prepend) { + $this->_columnNames = array_merge(array($fieldName => $name), $this->_columnNames); + $this->_fieldNames = array_merge(array($name => $fieldName), $this->_fieldNames); + } else { + $this->_columnNames[$fieldName] = $name; + $this->_fieldNames[$name] = $fieldName; + } + + if ($length == null) { + switch ($type) { + case 'string': + case 'clob': + case 'float': + case 'integer': + case 'array': + case 'object': + case 'blob': + case 'gzip': + // use php int max + $length = 2147483647; + break; + case 'boolean': + $length = 1; + case 'date': + // YYYY-MM-DD ISO 8601 + $length = 10; + case 'time': + // HH:NN:SS+00:00 ISO 8601 + $length = 14; + case 'timestamp': + // YYYY-MM-DDTHH:MM:SS+00:00 ISO 8601 + $length = 25; + break; + } + } + + $options['type'] = $type; + $options['length'] = $length; + + if ($prepend) { + $this->_columns = array_merge(array($name => $options), $this->_columns); + } else { + $this->_columns[$name] = $options; + } + + if ( ! empty($options['primary'])) { + if (isset($this->_identifier)) { + $this->_identifier = $this->_identifier; + } + if ( ! in_array($fieldName, (array) $this->_identifier)) { + $this->_identifier[] = $fieldName; + } + } + if (isset($options['default'])) { + $this->_hasDefaultValues = true; + } + + $this->columnCount++; + } + + /** + * hasDefaultValues + * returns true if this table has default values, otherwise false + * + * @return boolean + */ + public function hasDefaultValues() + { + return $this->_hasDefaultValues; + } + + /** + * getDefaultValueOf + * returns the default value(if any) for given column + * + * @param string $fieldName + * @return mixed + */ + public function getDefaultValueOf($fieldName) + { + $columnName = $this->getColumnName($fieldName); + if ( ! isset($this->_columns[$columnName])) { + throw new Doctrine_Table_Exception("Couldn't get default value. Column ".$columnName." doesn't exist."); + } + if (isset($this->_columns[$columnName]['default'])) { + return $this->_columns[$columnName]['default']; + } else { + return null; + } + } + + /** + * @return mixed + */ + public function getIdentifier() + { + return $this->_identifier; + } + + public function setIdentifier($identifier) + { + $this->_identifier = $identifier; + } + + /** + * @return integer + */ + public function getIdentifierType() + { + return $this->_identifierType; + } + + public function setIdentifierType($type) + { + $this->_identifierType = $type; + } + + /** + * hasColumn + * @return boolean + */ + public function hasColumn($columnName) + { + return isset($this->_columns[$columnName]); + } + + /** + * hasField + * @return boolean + */ + public function hasField($fieldName) + { + return isset($this->_columnNames[$fieldName]); + } + + /** + * @param string $fieldName + * @return array + */ + public function getEnumValues($fieldName) + { + $columnName = $this->getColumnName($fieldName); + if (isset($this->_columns[$columnName]['values'])) { + return $this->_columns[$columnName]['values']; + } else { + return array(); + } + } + + /** + * enumValue + * + * @param string $field + * @param integer $index + * @return mixed + */ + public function enumValue($fieldName, $index) + { + if ($index instanceof Doctrine_Null) { + return $index; + } + + $columnName = $this->getColumnName($fieldName); + if ( ! $this->_conn->getAttribute(Doctrine::ATTR_USE_NATIVE_ENUM) && + isset($this->_columns[$columnName]['values'][$index])) { + return $this->_columns[$columnName]['values'][$index]; + } + + return $index; + } + + /** + * enumIndex + * + * @param string $field + * @param mixed $value + * @return mixed + */ + public function enumIndex($fieldName, $value) + { + $values = $this->getEnumValues($fieldName); + $index = array_search($value, $values); + if ($index === false || ! $this->_conn->getAttribute(Doctrine::ATTR_USE_NATIVE_ENUM)) { + return $index; + } + + return $value; + } + + /** + * getColumnCount + * + * @return integer the number of columns in this table + */ + public function getColumnCount() + { + return $this->columnCount; + } + + /** + * returns all columns and their definitions + * + * @return array + */ + public function getColumns() + { + return $this->_columns; + } + + /** + * removeColumn + * removes given column + * + * @return boolean + */ + public function removeColumn($fieldName) + { + $columnName = array_search($fieldName, $this->_fieldNames); + + unset($this->_fieldNames[$columnName]); + + if (isset($this->_columns[$columnName])) { + unset($this->_columns[$columnName]); + return true; + } + $this->columnCount--; + + return false; + } + + /** + * returns an array containing all the column names. + * + * @return array + */ + public function getColumnNames(array $fieldNames = null) + { + if ($fieldNames === null) { + return array_keys($this->_columns); + } else { + $columnNames = array(); + foreach ($fieldNames as $fieldName) { + $columnNames[] = $this->getColumnName($fieldName); + } + + return $columnNames; + } + } + + /** + * returns an array with all the identifier column names. + * + * @return array + */ + public function getIdentifierColumnNames() + { + return $this->getColumnNames((array) $this->getIdentifier()); + } + + /** + * returns an array containing all the field names. + * + * @return array + */ + public function getFieldNames() + { + return array_values($this->_fieldNames); + } + + /** + * getDefinitionOf + * + * @return mixed array on success, false on failure + */ + public function getDefinitionOf($fieldName) + { + $columnName = $this->getColumnName($fieldName); + + return $this->getColumnDefinition($columnName); + } + + /** + * getTypeOf + * + * @return mixed string on success, false on failure + */ + public function getTypeOf($fieldName) + { + return $this->getTypeOfColumn($this->getColumnName($fieldName)); + } + + /** + * getTypeOfColumn + * + * @return mixed The column type or FALSE if the type cant be determined. + */ + public function getTypeOfColumn($columnName) + { + return isset($this->_columns[$columnName]) ? $this->_columns[$columnName]['type'] : false; + } + + /** + * getTableName + * + * @return void + */ + public function getTableName() + { + return $this->getTableOption('tableName'); + } + + /** + * + */ + public function getFieldMapping($fieldName) + { + return $this->getDefinitionOf($fieldName); + } + + /** + * + */ + public function getFields() + { + return $this->_columns; + } + + public function getInheritedFields() + { + + } + + public function getAllFields() + { + + } + + /** + * + * @param string $name The name under which the query gets registered. + * @param string $query The DQL query. + */ + public function setNamedQuery($name, $query) + { + + } + + public function bindRelation($args, $type) + { + return $this->bind($args, $type); + } + + /** + * DESCRIBE WHAT THIS METHOD DOES, PLEASE! + * + * @todo Name proposal: addRelation + */ + public function bind($args, $type) + { + $options = array(); + $options['type'] = $type; + + if ( ! isset($args[1])) { + $args[1] = array(); + } + if ( ! is_array($args[1])) { + try { + throw new Exception(); + } catch (Exception $e) { + echo $e->getTraceAsString(); + } + } + $options = array_merge($args[1], $options); + $this->_parser->bind($args[0], $options); + } + + /** + * hasRelation + * + * @param string $alias the relation to check if exists + * @return boolean true if the relation exists otherwise false + */ + public function hasRelation($alias) + { + return $this->_parser->hasRelation($alias); + } + + /** + * getRelation + * + * @param string $alias relation alias + */ + public function getRelation($alias, $recursive = true) + { + return $this->_parser->getRelation($alias, $recursive); + } + + public function getRelationParser() + { + return $this->_parser; + } + + /** + * getRelations + * returns an array containing all relation objects + * + * @return array an array of Doctrine_Relation objects + */ + public function getRelations() + { + return $this->_parser->getRelations(); + } + + /** + * getTemplates + * returns all templates attached to this table + * + * @return array an array containing all templates + */ + public function getTemplates() + { + return $this->_templates; + } + + /** + * Gets the inheritance type used by the class. + * + * @return integer + */ + public function getInheritanceType() + { + return $this->_inheritanceType; + } + + /** + * Sets the subclasses of the class. + * All entity classes that participate in a hierarchy and have subclasses + * need to declare them in this way. + * + * @param array $subclasses The names of all subclasses. + */ + public function setSubclasses(array $subclasses) + { + $this->setOption('subclasses', $subclasses); + } + + /** + * Gets the names of all subclasses. + * + * @return array The names of all subclasses. + */ + public function getSubclasses() + { + return $this->getOption('subclasses'); + } + + /** + * + */ + public function getParentClasses() + { + return $this->getOption('parents'); + } + + /** + * Sets the inheritance type used by the class. + * + * @param integer $type + */ + public function setInheritanceType($type, array $options = array()) + { + if ($type == Doctrine::INHERITANCETYPE_SINGLE_TABLE) { + $this->_checkRequiredDiscriminatorOptions($options); + } else if ($type == Doctrine::INHERITANCETYPE_JOINED) { + $this->_checkRequiredDiscriminatorOptions($options); + } else if ($type == Doctrine::INHERITANCETYPE_TABLE_PER_CLASS) { + // concrete table inheritance ... + } else { + throw new Doctrine_MetadataClass_Exception("Invalid inheritance type '$type'."); + } + $this->_inheritanceType = $type; + foreach ($options as $name => $value) { + $this->setInheritanceOption($name, $value); + } + } + + private function _checkRequiredDiscriminatorOptions(array $options) + { + if ( ! isset($options['discriminatorColumn'])) { + throw new Doctrine_ClassMetadata_Exception("Missing option 'discriminatorColumn'." + . " Inheritance types JOINED and SINGLE_TABLE require this option."); + } else if ( ! isset($options['discriminatorMap'])) { + throw new Doctrine_ClassMetadata_Exception("Missing option 'discriminatorMap'." + . " Inheritance types JOINED and SINGLE_TABLE require this option."); + } + } + + public function getInheritanceOption($name) + { + if ( ! array_key_exists($name, $this->_inheritanceOptions)) { + echo $name; + throw new Doctrine_ClassMetadata_Exception("Unknown inheritance option: '$name'."); + } + + return $this->_inheritanceOptions[$name]; + } + + public function getInheritanceOptions() + { + return $this->_inheritanceOptions; + } + + public function setInheritanceOption($name, $value) + { + if ( ! array_key_exists($name, $this->_inheritanceOptions)) { + throw new Doctrine_ClassMetadata_Exception("Unknown inheritance option: '$name'."); + } + + switch ($name) { + case 'discriminatorColumn': + if ( $value !== null && ! is_string($value)) { + throw new Doctrine_ClassMetadata_Exception("Invalid value '$value' for option" + . " 'discriminatorColumn'."); + } + break; + case 'discriminatorMap': + if ( ! is_array($value)) { + throw new Doctrine_ClassMetadata_Exception("Value for option 'discriminatorMap'" + . " must be an array."); + } + break; + } + + $this->_inheritanceOptions[$name] = $value; + } + + /** + * export + * exports this class to the database based on its mapping. + * + * @throws Doctrine_Connection_Exception If some error other than Doctrine::ERR_ALREADY_EXISTS + * occurred during the create table operation. + * @return boolean Whether or not the export operation was successful + * false if table already existed in the database. + */ + public function export() + { + $this->_conn->export->exportTable($this); + } + + /** + * getExportableFormat + * Returns an array with all the information needed to create the main database table + * for the class. + * + * @return array + * @todo Move somewhere else ... somehow this seems wrong here. Exporting is a separate task. + */ + public function getExportableFormat($parseForeignKeys = true) + { + $columns = array(); + $primary = array(); + $allColumns = $this->getColumns(); + + // If the class is part of a Single Table Inheritance hierarchy, collect the fields + // of all classes in the hierarchy. + if ($this->_inheritanceType == Doctrine::INHERITANCETYPE_SINGLE_TABLE) { + $parents = $this->getOption('parents'); + if ($parents) { + $rootClass = $this->_conn->getClassMetadata(array_pop($parents)); + } else { + $rootClass = $this; + } + $subClasses = $rootClass->getOption('subclasses'); + foreach ($subClasses as $subClass) { + $subClassMetadata = $this->_conn->getClassMetadata($subClass); + $allColumns = array_merge($allColumns, $subClassMetadata->getColumns()); + } + } else if ($this->_inheritanceType == Doctrine::INHERITANCETYPE_JOINED) { + // Remove inherited, non-pk fields. They're not in the table of this class + foreach ($allColumns as $name => $definition) { + if (isset($definition['primary']) && $definition['primary'] === true) { + if ($this->getParentClasses() && isset($definition['autoincrement'])) { + unset($allColumns[$name]['autoincrement']); + } + continue; + } + if (isset($definition['inherited']) && $definition['inherited'] === true) { + unset($allColumns[$name]); + } + } + } else if ($this->_inheritanceType == Doctrine::INHERITANCETYPE_TABLE_PER_CLASS) { + // If this is a subclass, just remove existing autoincrement options on the pk + if ($this->getParentClasses()) { + foreach ($allColumns as $name => $definition) { + if (isset($definition['primary']) && $definition['primary'] === true) { + if (isset($definition['autoincrement'])) { + unset($allColumns[$name]['autoincrement']); + } + } + } + } + } + + // Convert enum & boolean default values + foreach ($allColumns as $name => $definition) { + switch ($definition['type']) { + case 'enum': + if (isset($definition['default'])) { + $definition['default'] = $this->enumIndex($name, $definition['default']); + } + break; + case 'boolean': + if (isset($definition['default'])) { + $definition['default'] = $this->_conn->convertBooleans($definition['default']); + } + break; + } + $columns[$name] = $definition; + + if (isset($definition['primary']) && $definition['primary']) { + $primary[] = $name; + } + } + + // Collect foreign keys from the relations + $options['foreignKeys'] = array(); + if ($parseForeignKeys && $this->getAttribute(Doctrine::ATTR_EXPORT) + & Doctrine::EXPORT_CONSTRAINTS) { + $constraints = array(); + $emptyIntegrity = array('onUpdate' => null, 'onDelete' => null); + foreach ($this->getRelations() as $name => $relation) { + $fk = $relation->toArray(); + $fk['foreignTable'] = $relation->getTable()->getTableName(); + + if ($relation->getTable() === $this && in_array($relation->getLocal(), $primary)) { + if ($relation->hasConstraint()) { + throw new Doctrine_Table_Exception("Badly constructed integrity constraints."); + } + continue; + } + + $integrity = array('onUpdate' => $fk['onUpdate'], + 'onDelete' => $fk['onDelete']); + + if ($relation instanceof Doctrine_Relation_LocalKey) { + $def = array('local' => $relation->getLocal(), + 'foreign' => $relation->getForeign(), + 'foreignTable' => $relation->getTable()->getTableName()); + + if (($key = array_search($def, $options['foreignKeys'])) === false) { + $options['foreignKeys'][] = $def; + $constraints[] = $integrity; + } else { + if ($integrity !== $emptyIntegrity) { + $constraints[$key] = $integrity; + } + } + } + } + + foreach ($constraints as $k => $def) { + $options['foreignKeys'][$k] = array_merge($options['foreignKeys'][$k], $def); + } + } + + $options['primary'] = $primary; + + return array('tableName' => $this->getTableOption('tableName'), + 'columns' => $columns, + 'options' => array_merge($options, $this->getTableOptions())); + } + + /** + * getTemplate + * + * @param string $template + * @return void + */ + public function getTemplate($template) + { + if ( ! isset($this->_templates[$template])) { + throw new Doctrine_Table_Exception('Template ' . $template . ' not loaded'); + } + + return $this->_templates[$template]; + } + + public function hasTemplate($template) + { + return isset($this->_templates[$template]); + } + + public function addTemplate($template, Doctrine_Template $impl) + { + $this->_templates[$template] = $impl; + + return $this; + } + + public function getGenerators() + { + return $this->_generators; + } + + public function getGenerator($generator) + { + if ( ! isset($this->_generators[$generator])) { + throw new Doctrine_Table_Exception('Generator ' . $generator . ' not loaded'); + } + + return $this->_generators[$plugin]; + } + + public function hasGenerator($generator) + { + return isset($this->_generators[$generator]); + } + + public function addGenerator(Doctrine_Record_Generator $generator, $name = null) + { + if ($name === null) { + $this->_generators[] = $generator; + } else { + $this->_generators[$name] = $generator; + } + return $this; + } + + /** + * unshiftFilter + * + * @param object Doctrine_Record_Filter $filter + * @return object $this + */ + public function unshiftFilter(Doctrine_Record_Filter $filter) + { + $filter->setTable($this); + array_unshift($this->_filters, $filter); + + return $this; + } + + /** + * getTree + * + * getter for associated tree + * + * @return mixed if tree return instance of Doctrine_Tree, otherwise returns false + */ + public function getTree() + { + if ($this->getOption('treeImpl')) { + if ( ! $this->_tree) { + $options = $this->getOption('treeOptions') ? $this->getOption('treeOptions') : array(); + $this->_tree = Doctrine_Tree::factory($this, + $this->getOption('treeImpl'), $options); + } + return $this->_tree; + } + return false; + } + + /** + * isTree + * + * determine if table acts as tree + * + * @return mixed if tree return true, otherwise returns false + */ + public function isTree() + { + return ( ! is_null($this->getOption('treeImpl'))) ? true : false; + } + + /** + * getFilters + * + * @return array $filters + */ + public function getFilters() + { + return $this->_filters; + } + + /** + * + */ + public function isInheritedField($fieldName) + { + return isset($this->_columns[$this->getColumnName($fieldName)]['inherited']); + } + + /** + * bindQueryParts + * binds query parts to given component + * + * @param array $queryParts an array of pre-bound query parts + * @return Doctrine_Record this object + */ + public function bindQueryParts(array $queryParts) + { + $this->_options['queryParts'] = $queryParts; + return $this; + } + + /** + * bindQueryPart + * binds given value to given query part + * + * @param string $queryPart + * @param mixed $value + * @return Doctrine_Record this object + */ + public function bindQueryPart($queryPart, $value) + { + $this->_options['queryParts'][$queryPart] = $value; + return $this; + } + + /** + * getBoundQueryPart + * + * @param string $queryPart + * @return string $queryPart + */ + public function getBoundQueryPart($queryPart) + { + if ( ! isset($this->_options['queryParts'][$queryPart])) { + return null; + } + return $this->_options['queryParts'][$queryPart]; + } + + /** + * setTableName + * + * @param string $tableName + * @return void + */ + public function setTableName($tableName) + { + $this->setTableOption('tableName', $this->_conn->formatter->getTableName($tableName)); + } + + /** + * Serializes the metadata class. + * + * Part of the implementation of the Serializable interface. + * + * @return string The serialized metadata class. + */ + public function serialize() + { + return serialize($this->_columns); + } + + /** + * Reconstructs the metadata class from it's serialized representation. + * + * Part of the implementation of the Serializable interface. + * + * @param string $serialized The serialized metadata class. + */ + public function unserialize($serialized) + { + return true; + } + + /** + * + */ + public function oneToOne($targetEntity, $definition) + { + + } + + /** + * + */ + public function oneToMany($targetEntity, $definition) + { + + } + + /** + * + */ + public function manyToOne($targetEntity, $definition) + { + + } + + /** + * + */ + public function manyToMany($targetEntity, $definition) + { + + } + + /** + * loadTemplate + * + * @param string $template + */ + public function loadTemplate($template, array $options = array()) + { + $this->actAs($template, $options); + } + + public function loadGenerator(Doctrine_Record_Generator $generator) + { + $generator->initialize($this->_table); + $this->addGenerator($generator, get_class($generator)); + } + + + /** + * actAs + * loads the given plugin + * + * @param mixed $tpl + * @param array $options + */ + public function actAs($tpl, array $options = array()) + { + if ( ! is_object($tpl)) { + if (class_exists($tpl, true)) { + $tpl = new $tpl($options); + } else { + $className = 'Doctrine_Template_' . $tpl; + + if ( ! class_exists($className, true)) { + throw new Doctrine_Record_Exception("Couldn't load plugin."); + } + + + $tpl = new $className($options); + } + } + + if ( ! ($tpl instanceof Doctrine_Template)) { + throw new Doctrine_Record_Exception('Loaded plugin class is not an instance of Doctrine_Template.'); + } + + $className = get_class($tpl); + + $this->addTemplate($className, $tpl); + + $tpl->setTable($this); + $tpl->setUp(); + $tpl->setTableDefinition(); + + return $this; + } + + /** + * check + * adds a check constraint + * + * @param mixed $constraint either a SQL constraint portion or an array of CHECK constraints + * @param string $name optional constraint name + * @return Doctrine_Record this object + * @todo Should be done through $_tableOptions + */ + public function check($constraint, $name = null) + { + if (is_array($constraint)) { + foreach ($constraint as $name => $def) { + $this->_addCheckConstraint($def, $name); + } + } else { + $this->_addCheckConstraint($constraint, $name); + } + + return $this; + } + + protected function _addCheckConstraint($definition, $name) + { + if (is_string($name)) { + $this->_tableOptions['checks'][$name] = $definition; + } else { + $this->_tableOptions['checks'][] = $definition; + } + } + + /** + * Mixes a predefined behaviour into the class. + * + * @param string|object The name of the behavior or the behavior object. + */ + public function addBehavior($behavior) + { + // ... + } + + /** + * + */ + public function setType($type) + { + //Doctrine::CLASSTYPE_ENTITY + //Doctrine::CLASSTYPE_MAPPED_SUPERCLASS + //Doctrine::CLASSTYPE_TRANSIENT + } + + /** + * hasOne + * binds One-to-One aggregate relation + * + * @param string $componentName the name of the related component + * @param string $options relation options + * @see Doctrine_Relation::_$definition + * @return Doctrine_Record this object + */ + public function hasOne() + { + $this->bind(func_get_args(), Doctrine_Relation::ONE_AGGREGATE); + + return $this; + } + + /** + * hasMany + * binds One-to-Many / Many-to-Many aggregate relation + * + * @param string $componentName the name of the related component + * @param string $options relation options + * @see Doctrine_Relation::_$definition + * @return Doctrine_Record this object + */ + public function hasMany() + { + $this->bind(func_get_args(), Doctrine_Relation::MANY_AGGREGATE); + + return $this; + } + + /** + * + */ + public function __toString() + { + return spl_object_hash($this); + } +} + diff --git a/lib/Doctrine/ClassMetadata/CodeDriver.php b/lib/Doctrine/ClassMetadata/CodeDriver.php new file mode 100644 index 000000000..67b409753 --- /dev/null +++ b/lib/Doctrine/ClassMetadata/CodeDriver.php @@ -0,0 +1,18 @@ + + */ +class Doctrine_ClassMetadata_CodeDriver +{ + /** + * Loads the metadata for the specified class into the provided container. + */ + public function loadMetadataForClass($className, Doctrine_ClassMetadata $metadata) + { + call_user_func_array(array($className, 'initMetadata'), array($metadata)); + } +} \ No newline at end of file diff --git a/lib/Doctrine/ClassMetadata/Exception.php b/lib/Doctrine/ClassMetadata/Exception.php new file mode 100644 index 000000000..29f2b1163 --- /dev/null +++ b/lib/Doctrine/ClassMetadata/Exception.php @@ -0,0 +1,3 @@ +_conn = $conn; + $this->_driver = $driver; + } + + /** + * Returns the metadata object for a class. + * + * @param string $className The name of the class. + * @return Doctrine_Metadata + */ + public function getMetadataFor($className) + { + if (isset($this->_loadedMetadata[$className])) { + return $this->_loadedMetadata[$className]; + } + $this->_loadClasses($className, $this->_loadedMetadata); + + return $this->_loadedMetadata[$className]; + } + + /** + * Loads the metadata of the class in question and all it's ancestors whose metadata + * is still not loaded. + * + * @param string $name The name of the class for which the metadata should get loaded. + * @param array $tables The metadata collection to which the loaded metadata is added. + */ + protected function _loadClasses($name, array &$classes) + { + $parentClass = $name; + $parentClasses = array(); + $loadedParentClass = false; + while ($parentClass = get_parent_class($parentClass)) { + if ($parentClass == 'Doctrine_Record') { + break; + } + if (isset($classes[$parentClass])) { + $loadedParentClass = $parentClass; + break; + } + $parentClasses[] = $parentClass; + } + $parentClasses = array_reverse($parentClasses); + $parentClasses[] = $name; + + if ($loadedParentClass) { + $class = $classes[$loadedParentClass]; + } else { + $rootClassOfHierarchy = count($parentClasses) > 0 ? array_shift($parentClasses) : $name; + $class = new Doctrine_ClassMetadata($rootClassOfHierarchy, $this->_conn); + $this->_loadMetadata($class, $rootClassOfHierarchy); + $classes[$rootClassOfHierarchy] = $class; + } + + if (count($parentClasses) == 0) { + return $class; + } + + // load metadata of subclasses + // -> child1 -> child2 -> $name + + $parent = $class; + foreach ($parentClasses as $subclassName) { + $subClass = new Doctrine_ClassMetadata($subclassName, $this->_conn); + $subClass->setInheritanceType($parent->getInheritanceType(), $parent->getInheritanceOptions()); + $this->_addInheritedFields($subClass, $parent); + $this->_addInheritedRelations($subClass, $parent); + $this->_loadMetadata($subClass, $subclassName); + if ($parent->getInheritanceType() == Doctrine::INHERITANCETYPE_SINGLE_TABLE) { + //echo "
". $subClass->getClassName() . $parent->getTableName() . "
"; + $subClass->setTableName($parent->getTableName()); + } + $classes[$subclassName] = $subClass; + $parent = $subClass; + } + } + + protected function _addInheritedFields($subClass, $parentClass) + { + foreach ($parentClass->getColumns() as $name => $definition) { + /*if (isset($definition['autoincrement']) && $definition['autoincrement'] === true) { + unset($definition['autoincrement']); + }*/ + $fullName = "$name as " . $parentClass->getFieldName($name); + $definition['inherited'] = true; + $subClass->setColumn($fullName, $definition['type'], $definition['length'], + $definition); + } + } + + protected function _addInheritedRelations($subClass, $parentClass) { + foreach ($parentClass->getRelationParser()->getRelations() as $name => $relation) { + $subClass->getRelationParser()->addRelation($name, $relation); + } + } + + /** + * Current code driver. + */ + protected function _loadMetadata(Doctrine_ClassMetadata $class, $name) + { + if ( ! class_exists($name) || empty($name)) { + /*try { + throw new Exception(); + } catch (Exception $e) { + echo $e->getTraceAsString(); + }*/ + throw new Doctrine_Exception("Couldn't find class " . $name . "."); + } + + $names = array(); + $className = $name; + // get parent classes + do { + if ($className === 'Doctrine_Record') { + break; + } else if ($className == $name) { + continue; + } + $names[] = $className; + } while ($className = get_parent_class($className)); + + if ($className === false) { + throw new Doctrine_ClassMetadata_Factory_Exception("Unknown component '$className'."); + } + + // save parents + $class->setOption('parents', $names); + + // load further metadata + $this->_driver->loadMetadataForClass($name, $class); + + $tableName = $class->getTableName(); + if ( ! isset($tableName)) { + $class->setTableName(Doctrine::tableize($class->getClassName())); + } + + $this->_initIdentifier($class); + + return $class; + } + + /** + * Code driver. + * + * @todo Move to code driver. + */ + /*protected function _loadMetadataFromCode($class, $name) + { + call_user_func_array(array($name, 'initMetadata'), array($class)); + }*/ + + /** + * Initializes the class identifier(s)/primary key(s). + * + * @param Doctrine_Metadata The metadata container of the class in question. + */ + protected function _initIdentifier(Doctrine_ClassMetadata $class) + { + switch (count($class->getIdentifier())) { + case 0: + if ($class->getInheritanceType() == Doctrine::INHERITANCETYPE_JOINED && + count($class->getOption('parents')) > 0) { + + $parents = $class->getOption('parents'); + $root = end($parents); + $rootClass = $class->getConnection()->getMetadata($root); + $class->setIdentifier($rootClass->getIdentifier()); + + if ($class->getIdentifierType() !== Doctrine::IDENTIFIER_AUTOINC) { + $class->setIdentifierType($rootClass->getIdentifierType()); + } else { + $class->setIdentifierType(Doctrine::IDENTIFIER_NATURAL); + } + + // add all inherited primary keys + foreach ((array) $class->getIdentifier() as $id) { + $definition = $rootClass->getDefinitionOf($id); + + // inherited primary keys shouldn't contain autoinc + // and sequence definitions + unset($definition['autoincrement']); + unset($definition['sequence']); + + // add the inherited primary key column + $fullName = $rootClass->getColumnName($id) . ' as ' . $id; + $class->setColumn($fullName, $definition['type'], $definition['length'], + $definition, true); + } + } else { + $definition = array('type' => 'integer', + 'length' => 20, + 'autoincrement' => true, + 'primary' => true); + $class->setColumn('id', $definition['type'], $definition['length'], $definition, true); + $class->setIdentifier('id'); + $class->setIdentifierType(Doctrine::IDENTIFIER_AUTOINC); + } + break; + case 1: + foreach ($class->getIdentifier() as $pk) { + $columnName = $class->getColumnName($pk); + $thisColumns = $class->getColumns(); + $e = $thisColumns[$columnName]; + + $found = false; + + foreach ($e as $option => $value) { + if ($found) { + break; + } + + $e2 = explode(':', $option); + + switch (strtolower($e2[0])) { + case 'autoincrement': + case 'autoinc': + $class->setIdentifierType(Doctrine::IDENTIFIER_AUTOINC); + $found = true; + break; + case 'seq': + case 'sequence': + $class->setIdentifierType(Doctrine::IDENTIFIER_SEQUENCE); + $found = true; + + if ($value) { + $class->setOption('sequenceName', $value); + } else { + if (($sequence = $class->getAttribute(Doctrine::ATTR_DEFAULT_SEQUENCE)) !== null) { + $class->setOption('sequenceName', $sequence); + } else { + $class->setOption('sequenceName', $class->getConnection() + ->getSequenceName($class->getOption('tableName'))); + } + } + break; + } + } + $identifierType = $class->getIdentifierType(); + if ( ! isset($identifierType)) { + $class->setIdentifierType(Doctrine::IDENTIFIER_NATURAL); + } + } + + $class->setIdentifier($pk); + + break; + default: + $class->setIdentifierType(Doctrine::IDENTIFIER_COMPOSITE); + } + } + +} + + + diff --git a/lib/Doctrine/ClassMetadata/YamlDriver.php b/lib/Doctrine/ClassMetadata/YamlDriver.php new file mode 100644 index 000000000..e9549213e --- /dev/null +++ b/lib/Doctrine/ClassMetadata/YamlDriver.php @@ -0,0 +1,16 @@ +. - */ - -/** - * Doctrine_Column - * This class represents a database column - * - * @author Konsta Vesterinen - * @package Doctrine - * @subpackage Column - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @version $Revision$ - * @link www.phpdoctrine.com - * @since 1.0 - */ -class Doctrine_Column extends Doctrine_Access implements IteratorAggregate, Countable -{ - /** - * @var array $definition - */ - protected $_definition = array( - 'type' => null, - 'length' => 0, - ); - - /** - * @var array $definition - */ - public function __construct(array $definition = array()) - { - $this->_definition = $definition; - } - - /** - * @return array - */ - public function getDefinition() - { - return $this->_definition; - } - - /** - * contains - * - * @return boolean - */ - public function contains($name) - { - return isset($this->_definition[$name]); - } - - /** - * get - * - * @param string $name - * @return mixed - */ - public function get($name) - { - if ( ! isset($this->_definition[$name])) { - return null; - } - - return $this->_definition[$name]; - } - - /** - * set - * - * @param string $name - * @return mixed - */ - public function set($name, $value) - { - $this->_definition[$name] = $value; - } - - /** - * @param string $field - * @return array - */ - public function getEnumValues() - { - if (isset($this->_definition['values'])) { - return $this->_definition['values']; - } else { - return array(); - } - } - - /** - * enumValue - * - * @param string $field - * @param integer $index - * @return mixed - */ - public function enumValue($index) - { - if ($index instanceof Doctrine_Null) { - return $index; - } - - return isset($this->_definition['values'][$index]) ? $this->_definition['values'][$index] : $index; - } - - /** - * enumIndex - * - * @param string $field - * @param mixed $value - * @return mixed - */ - public function enumIndex($field, $value) - { - $values = $this->getEnumValues($field); - - return array_search($value, $values); - } - - /** - * count - * - * @return integer - */ - public function count() - { - return count($this->_definition); - } - - /** - * getIterator - * - * @return ArrayIterator - */ - public function getIterator() - { - return new ArrayIterator($this->_definition); - } -} \ No newline at end of file diff --git a/lib/Doctrine/Configurable.php b/lib/Doctrine/Configurable.php index 9ae26f12d..1e35963bf 100644 --- a/lib/Doctrine/Configurable.php +++ b/lib/Doctrine/Configurable.php @@ -111,8 +111,8 @@ abstract class Doctrine_Configurable extends Doctrine_Locator_Injectable $this->setEventListener($value); break; case Doctrine::ATTR_COLL_KEY: - if ( ! ($this instanceof Doctrine_Table)) { - throw new Doctrine_Exception("This attribute can only be set at table level."); + if ( ! ($this instanceof Doctrine_ClassMetadata)) { + throw new Doctrine_Exception("This attribute can only be set at class level."); } if ($value !== null && ! $this->hasField($value)) { throw new Doctrine_Exception("Couldn't set collection key attribute. No such field '$value'"); @@ -320,6 +320,11 @@ abstract class Doctrine_Configurable extends Doctrine_Locator_Injectable return $this; } + /* + public function removeRecordListeners() + { + $this->attributes[Doctrine::ATTR_RECORD_LISTENER] = + }*/ /** * addListener @@ -364,8 +369,7 @@ abstract class Doctrine_Configurable extends Doctrine_Locator_Injectable public function setListener($listener) { if ( ! ($listener instanceof Doctrine_EventListener_Interface) - && ! ($listener instanceof Doctrine_Overloadable) - ) { + && ! ($listener instanceof Doctrine_Overloadable)) { throw new Doctrine_EventListener_Exception("Couldn't set eventlistener. EventListeners should implement either Doctrine_EventListener_Interface or Doctrine_Overloadable"); } $this->attributes[Doctrine::ATTR_LISTENER] = $listener; diff --git a/lib/Doctrine/Connection.php b/lib/Doctrine/Connection.php index f883811ed..83e4383eb 100644 --- a/lib/Doctrine/Connection.php +++ b/lib/Doctrine/Connection.php @@ -56,23 +56,23 @@ Doctrine::autoload('Doctrine_Configurable'); abstract class Doctrine_Connection extends Doctrine_Configurable implements Countable, IteratorAggregate { /** - * @var $dbh the database handler + * The PDO database handle. + * + * @var PDO */ protected $dbh; /** + * The metadata factory is used to retrieve the metadata of classes. * + * @var Doctrine_ClassMetadata_Factory */ - protected $_tableFactory; + protected $_metadataFactory; /** - * @var array $tables an array containing all the initialized Doctrine_Table objects - * keys representing component names and values as Doctrine_Table objects - */ - protected $tables = array(); - - /** - * @var array An array of mapper objects currently maintained by this connection. + * An array of mapper objects currently maintained by this connection. + * + * @var array */ protected $_mappers = array(); @@ -86,19 +86,24 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun protected $_name; /** - * @var string $driverName the name of this connection driver + * The name of this connection driver. + * + * @var string $driverName */ protected $driverName; /** - * @var boolean $isConnected whether or not a connection has been established + * Whether or not a connection has been established. + * + * @var boolean $isConnected */ - protected $isConnected = false; + protected $isConnected = false; /** - * @var array $supported an array containing all features this driver supports, - * keys representing feature names and values as - * one of the following (true, false, 'emulated') + * An array containing all features this driver supports, keys representing feature + * names and values as one of the following (true, false, 'emulated'). + * + * @var array $supported */ protected $supported = array(); @@ -167,12 +172,15 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun */ protected $serverInfo = array(); + /** + * + */ protected $options = array(); /** * @var array $availableDrivers an array containing all available drivers */ - private static $availableDrivers = array( + private static $availableDrivers = array( 'Mysql', 'Pgsql', 'Oracle', @@ -383,12 +391,12 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun public function getDbh() { $this->connect(); + return $this->dbh; } /** - * connect - * connects into database + * Establishes the connection with the database. * * @return boolean */ @@ -401,7 +409,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun $event = new Doctrine_Event($this, Doctrine_Event::CONN_CONNECT); $this->getListener()->preConnect($event); - $e = explode(':', $this->options['dsn']); + $e = explode(':', $this->options['dsn']); $found = false; if (extension_loaded('pdo')) { @@ -438,8 +446,11 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun $this->getListener()->postConnect($event); return true; } - - public function incrementQueryCount() + + /** + * @todo Remove. Breaks encapsulation. + */ + public function incrementQueryCount() { $this->_count++; } @@ -450,8 +461,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun * @param */ public function driverName($name) - { - } + {} /** * supports @@ -498,7 +508,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun * @throws Doctrine_Connection_Exception if some of the key values was null * @throws Doctrine_Connection_Exception if there were no key fields * @throws PDOException if something fails at PDO level - * @ return integer number of rows affected + * @return integer number of rows affected */ public function replace(Doctrine_Table $table, array $fields, array $keys) { @@ -537,8 +547,11 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun * @param string $table The table to delete data from * @param array $identifier An associateve array containing identifier fieldname-value pairs. * @return integer The number of affected rows + * + * @todo First argument should just be a table name. Move the conversion from + * field to column names one layer up. */ - public function delete(Doctrine_Table $table, array $identifier) + public function delete(Doctrine_ClassMetadata $table, array $identifier) { $criteria = array(); foreach (array_keys($identifier) as $id) { @@ -560,8 +573,11 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun * @param array $values An associateve array containing column-value pairs. * @return mixed boolean false if empty value array was given, * otherwise returns the number of affected rows + * + * @todo First argument should just be a table name. Move the conversion from + * field to column names one layer up. */ - public function update(Doctrine_Table $table, array $fields, array $identifier) + public function update(Doctrine_ClassMetadata $table, array $fields, array $identifier) { if (empty($fields)) { return false; @@ -594,8 +610,11 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun * @param array $fields An associateve array containing fieldname-value pairs. * @return mixed boolean false if empty value array was given, * otherwise returns the number of affected rows + * + * @todo First argument should just be a table name. Move the conversion from + * field to column names one layer up. */ - public function insert(Doctrine_Table $table, array $fields) + public function insert(Doctrine_ClassMetadata $table, array $fields) { if (empty($fields)) { return false; @@ -933,6 +952,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun try { if ( ! empty($params)) { + //echo $query . "
"; $stmt = $this->prepare($query); $stmt->execute($params); return $stmt; @@ -1008,6 +1028,10 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun $event = new Doctrine_Event($this, Doctrine_Event::CONN_ERROR); $this->getListener()->preError($event); + /*if (strstr($e->getMessage(), 'no such column')) { + echo $e->getMessage() . "
" . $e->getTraceAsString() . "
"; + }*/ + $name = 'Doctrine_Connection_' . $this->driverName . '_Exception'; $exc = new $name($e->getMessage(), (int) $e->getCode()); @@ -1036,31 +1060,49 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun } /** - * Gets the table object that represents the database table that is used to - * persist the specified domain class. + * Returns the metadata for a class. * - * @param string $name component name - * @return Doctrine_Table + * @return Doctrine_Metadata + * @todo package:orm */ - public function getTable($className) + public function getMetadata($className) { - if (isset($this->tables[$className])) { - return $this->tables[$className]; - } - - if (!($this->_tableFactory instanceOf Doctrine_Table_Factory)) { - $this->_tableFactory = new Doctrine_Table_Factory($this); - } - - $this->_tableFactory->loadTables($className, $this->tables); - return $this->tables[$className]; + return $this->getClassMetadata($className); } + /** + * Returns the metadata for a class. + * + * @return Doctrine_Metadata + * @todo package:orm + */ + public function getClassMetadata($className) + { + if ( ! $this->_metadataFactory) { + $this->_metadataFactory = new Doctrine_ClassMetadata_Factory($this, + new Doctrine_ClassMetadata_CodeDriver()); + } + + return $this->_metadataFactory->getMetadataFor($className); + } + + /** + * Sets the driver that is used to obtain metadata informations about entity + * classes. + * + * @param $driver The driver to use. + */ + public function setClassMetadataDriver($driver) + { + $this->_metadataFactory->setDriver($driver); + } + /** * Gets a mapper for the specified domain class that is used to map instances of * the class between the relational database and their object representation. * - * @return Doctrine_Mapper_Abstract The mapper object. + * @return Doctrine_Mapper The mapper object. + * @todo package:orm */ public function getMapper($className) { @@ -1069,20 +1111,19 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun } $customMapperClass = $className . 'Mapper'; + $metadata = $this->getMetadata($className); if (class_exists($customMapperClass, $this->getAttribute(Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES)) && in_array('Doctrine_Mapper_Abstract', class_parents($customMapperClass))) { - $table = $this->getTable($className); - $mapper = new $customMapperClass($className, $table); + $mapper = new $customMapperClass($className, $metadata); } else { // instantiate correct mapper type - $table = $this->getTable($className); - $inheritanceType = $table->getInheritanceType(); + $inheritanceType = $metadata->getInheritanceType(); if ($inheritanceType == Doctrine::INHERITANCETYPE_JOINED) { - $mapper = new Doctrine_Mapper_Joined($className, $table); + $mapper = new Doctrine_Mapper_Joined($className, $metadata); } else if ($inheritanceType == Doctrine::INHERITANCETYPE_SINGLE_TABLE) { - $mapper = new Doctrine_Mapper_SingleTable($className, $table); + $mapper = new Doctrine_Mapper_SingleTable($className, $metadata); } else if ($inheritanceType == Doctrine::INHERITANCETYPE_TABLE_PER_CLASS) { - $mapper = new Doctrine_Mapper_TablePerClass($className, $table); + $mapper = new Doctrine_Mapper_TablePerClass($className, $metadata); } else { throw new Doctrine_Connection_Exception("Unknown inheritance type '$inheritanceType'. Can't create mapper."); } @@ -1094,23 +1135,17 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun } /** - * returns an array of all initialized tables + * Gets all mappers that are currently maintained by the connection. * - * @return array + * @todo package:orm */ - public function getTables() - { - return $this->tables; - } - public function getMappers() { - //var_dump($this->_mappers); return $this->_mappers; } /** - * returns an iterator that iterators through all + * returns an iterator that iterates through all * initialized table objects * * @@ -1127,33 +1162,16 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun } /** - * returns the count of initialized table objects + * Returns the number of queries executed by the connection. * * @return integer + * @todo Better name: getQueryCount() */ public function count() { return $this->_count; } - /** - * addTable - * adds a Doctrine_Table object into connection registry - * - * @param $table a Doctrine_Table object to be added into registry - * @return boolean - */ - public function addTable(Doctrine_Table $table) - { - $name = $table->getComponentName(); - - if (isset($this->tables[$name])) { - return false; - } - $this->tables[$name] = $table; - return true; - } - /** * create * creates a record @@ -1161,6 +1179,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun * create creates a record * @param string $name component name * @return Doctrine_Record Doctrine_Record object + * @todo Any strong reasons why this should not be removed? + * @todo package:orm */ public function create($name) { @@ -1169,12 +1189,18 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun /** * Creates a new Doctrine_Query object that operates on this connection. - * + * * @return Doctrine_Query + * @todo package:orm */ - public function createQuery() + public function createQuery($dql = "") { - return new Doctrine_Query($this); + $query = new Doctrine_Query($this); + if ( ! empty($dql)) { + $query->parseQuery($dql); + } + + return $query; } /** @@ -1184,6 +1210,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun * * @throws PDOException if something went wrong at database level * @return void + * @todo package:orm */ public function flush() { @@ -1197,6 +1224,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun * clears all repositories * * @return void + * @todo package:orm */ public function clear() { @@ -1211,6 +1239,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun * evicts all tables * * @return void + * @todo package:orm */ public function evictTables() { @@ -1220,8 +1249,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun } /** - * close - * closes the connection + * Closes the connection. * * @return void */ @@ -1239,9 +1267,9 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun } /** - * get the current transaction nesting level + * Returns the current total transaction nesting level. * - * @return integer + * @return integer The nesting level. A value of 0 means theres no active transaction. */ public function getTransactionLevel() { @@ -1249,9 +1277,10 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun } /** - * get the current internal transaction nesting level + * Returns the current internal transaction nesting level. * - * @return integer + * @return integer The nesting level. A value of 0 means theres no active transaction. + * @todo package:orm??? */ public function getInternalTransactionLevel() { @@ -1267,6 +1296,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun public function errorCode() { $this->connect(); + return $this->dbh->errorCode(); } @@ -1279,6 +1309,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun public function errorInfo() { $this->connect(); + return $this->dbh->errorInfo(); } @@ -1297,12 +1328,14 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun * getResultCacheDriver * * @return Doctrine_Cache_Interface + * @todo package:orm */ public function getResultCacheDriver() { if ( ! $this->getAttribute(Doctrine::ATTR_RESULT_CACHE)) { throw new Doctrine_Exception('Result Cache driver not initialized.'); } + return $this->getAttribute(Doctrine::ATTR_RESULT_CACHE); } @@ -1310,12 +1343,14 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun * getQueryCacheDriver * * @return Doctrine_Cache_Interface + * @todo package:orm */ public function getQueryCacheDriver() { if ( ! $this->getAttribute(Doctrine::ATTR_QUERY_CACHE)) { throw new Doctrine_Exception('Query Cache driver not initialized.'); } + return $this->getAttribute(Doctrine::ATTR_QUERY_CACHE); } @@ -1328,8 +1363,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun * Note: This method may not return a meaningful or consistent result across different drivers, * because the underlying database may not even support the notion of auto-increment fields or sequences. * - * @param string $table name of the table into which a new row was inserted - * @param string $field name of the field into which a new row was inserted + * @param string $table Name of the table into which a new row was inserted. + * @param string $field Name of the field into which a new row was inserted. */ public function lastInsertId($table = null, $field = null) { @@ -1359,6 +1394,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun * * This method must only be used by Doctrine itself to initiate transactions. * Userland-code must use {@link beginTransaction()}. + * + * @todo package:orm??? */ public function beginInternalTransaction($savepoint = null) { diff --git a/lib/Doctrine/Export.php b/lib/Doctrine/Export.php index 81fc6ac67..a3eb6dc5d 100644 --- a/lib/Doctrine/Export.php +++ b/lib/Doctrine/Export.php @@ -1068,7 +1068,7 @@ class Doctrine_Export extends Doctrine_Connection_Module * @return void */ public function exportClasses(array $classes) - { + { $connections = array(); foreach ($classes as $class) { $record = new $class(); @@ -1083,6 +1083,7 @@ class Doctrine_Export extends Doctrine_Connection_Module } $sql = $this->exportClassesSql(array($class)); + // Build array of all the creates // We need these to happen first foreach ($sql as $key => $query) { @@ -1137,29 +1138,37 @@ class Doctrine_Export extends Doctrine_Connection_Module * occurred during the create table operation * @param array $classes * @return void + * @todo package:orm */ public function exportClassesSql(array $classes) { $models = Doctrine::filterInvalidModels($classes); $sql = array(); - + $finishedClasses = array(); + foreach ($models as $name) { - $record = new $name(); - $table = $record->getTable(); - - $parents = $table->getOption('joinedParents'); - - foreach ($parents as $parent) { - $data = $table->getConnection()->getTable($parent)->getExportableFormat(); - - $query = $this->conn->export->createTableSql($data['tableName'], $data['columns'], $data['options']); - - $sql = array_merge($sql, (array) $query); + if (in_array($name, $finishedClasses)) { + continue; } - - $data = $table->getExportableFormat(); - + + $classMetadata = $this->conn->getClassMetadata($name); + + // In Class Table Inheritance we have to make sure that ALL tables are exported + // as soon as ONE table is exported, because the data of one class is stored + // across many tables. + if ($classMetadata->getInheritanceType() == Doctrine::INHERITANCETYPE_JOINED) { + //echo "joined.
"; + $parents = $classMetadata->getOption('parents'); + foreach ($parents as $parent) { + $data = $classMetadata->getConnection()->getClassMetadata($parent)->getExportableFormat(); + $query = $this->conn->export->createTableSql($data['tableName'], $data['columns'], $data['options']); + $sql = array_merge($sql, (array) $query); + $finishedClasses[] = $parent; + } + } + + $data = $classMetadata->getExportableFormat(); $query = $this->conn->export->createTableSql($data['tableName'], $data['columns'], $data['options']); if (is_array($query)) { @@ -1168,8 +1177,8 @@ class Doctrine_Export extends Doctrine_Connection_Module $sql[] = $query; } - if ($table->getAttribute(Doctrine::ATTR_EXPORT) & Doctrine::EXPORT_PLUGINS) { - $sql = array_merge($sql, $this->exportGeneratorsSql($table)); + if ($classMetadata->getAttribute(Doctrine::ATTR_EXPORT) & Doctrine::EXPORT_PLUGINS) { + $sql = array_merge($sql, $this->exportGeneratorsSql($classMetadata)); } } @@ -1185,8 +1194,9 @@ class Doctrine_Export extends Doctrine_Connection_Module * * @param Doctrine_Table $table table object to retrieve the generators from * @return array an array of Doctrine_Record_Generator objects + * @todo package:orm */ - public function getAllGenerators(Doctrine_Table $table) + public function getAllGenerators(Doctrine_ClassMetadata $table) { $generators = array(); @@ -1213,11 +1223,12 @@ class Doctrine_Export extends Doctrine_Connection_Module * * @param Doctrine_Table $table the table in which the generators belong to * @return array an array of sql strings + * @todo package:orm */ - public function exportGeneratorsSql(Doctrine_Table $table) + public function exportGeneratorsSql(Doctrine_ClassMetadata $class) { $sql = array(); - foreach ($this->getAllGenerators($table) as $name => $generator) { + foreach ($this->getAllGenerators($class) as $name => $generator) { $table = $generator->getTable(); // Make sure plugin has a valid table diff --git a/lib/Doctrine/Hydrator.php b/lib/Doctrine/Hydrator.php index bae4f1a91..7d8b6c773 100644 --- a/lib/Doctrine/Hydrator.php +++ b/lib/Doctrine/Hydrator.php @@ -60,16 +60,15 @@ class Doctrine_Hydrator extends Doctrine_Hydrator_Abstract */ public function hydrateResultSet($stmt, $tableAliases, $hydrationMode = null) { - //$s = microtime(true); - $this->_tableAliases = $tableAliases; + if ($hydrationMode === null) { + $hydrationMode = $this->_hydrationMode; + } if ($hydrationMode == Doctrine::HYDRATE_NONE) { return $stmt->fetchAll(PDO::FETCH_NUM); } - if ($hydrationMode === null) { - $hydrationMode = $this->_hydrationMode; - } + $this->_tableAliases = $tableAliases; if ($hydrationMode === Doctrine::HYDRATE_ARRAY) { $driver = new Doctrine_Hydrator_ArrayDriver(); @@ -108,7 +107,7 @@ class Doctrine_Hydrator extends Doctrine_Hydrator_Abstract foreach ($this->_queryComponents as $dqlAlias => $data) { $data['mapper']->setAttribute(Doctrine::ATTR_LOAD_REFERENCES, false); $componentName = $data['mapper']->getComponentName(); - $listeners[$componentName] = $data['table']->getRecordListener(); + $listeners[$componentName] = $data['mapper']->getRecordListener(); $identifierMap[$dqlAlias] = array(); $prev[$dqlAlias] = array(); $id[$dqlAlias] = ''; diff --git a/lib/Doctrine/Hydrator/ArrayDriver.php b/lib/Doctrine/Hydrator/ArrayDriver.php index 67383e932..a05eea4f1 100644 --- a/lib/Doctrine/Hydrator/ArrayDriver.php +++ b/lib/Doctrine/Hydrator/ArrayDriver.php @@ -20,8 +20,8 @@ */ /** - * Doctrine_Hydrate_Array - * defines an array fetching strategy for Doctrine_Hydrate + * Doctrine_Hydrator_ArrayDriver + * Defines an array fetching strategy. * * @package Doctrine * @subpackage Hydrate @@ -33,47 +33,69 @@ */ class Doctrine_Hydrator_ArrayDriver { + /** + * + */ public function getElementCollection($component) { return array(); } + /** + * + */ public function getElement(array $data, $component) { return $data; } + /** + * + */ public function isIdentifiable(array $data, Doctrine_Table $table) { return ( ! empty($data)); } + /** + * + */ public function registerCollection($coll) - { - - } + { /* Nothing to do */ } + /** + * + */ public function initRelated(array &$data, $name) { if ( ! isset($data[$name])) { $data[$name] = array(); } + return true; } + /** + * + */ public function getNullPointer() { return null; } + /** + * + */ public function getLastKey(&$data) { end($data); + return key($data); } - + + /** + * + */ public function flush() - { - - } + { /* Nothing to do */ } } diff --git a/lib/Doctrine/Hydrator/RecordDriver.php b/lib/Doctrine/Hydrator/RecordDriver.php index 348498539..8e02a03a9 100644 --- a/lib/Doctrine/Hydrator/RecordDriver.php +++ b/lib/Doctrine/Hydrator/RecordDriver.php @@ -104,11 +104,11 @@ class Doctrine_Hydrator_RecordDriver extends Doctrine_Locator_Injectable public function getElement(array $data, $component) { + $component = $this->_getClassnameToReturn($data, $component); if ( ! isset($this->_mappers[$component])) { $this->_mappers[$component] = Doctrine_Manager::getInstance()->getMapper($component); } - - $component = $this->_getClassnameToReturn($data, $component); + $record = $this->_mappers[$component]->getRecord($data); if ( ! isset($this->_records[$record->getOid()]) ) { @@ -128,35 +128,31 @@ class Doctrine_Hydrator_RecordDriver extends Doctrine_Locator_Injectable } /** - * Check the dataset for a discriminator column, to determine the correct + * Check the dataset for a discriminator column to determine the correct * class to instantiate. If no discriminator column is found, the given * classname will be returned. * - * @todo this function could use reflection to check the first time it runs - * if the subclassing option is not set. - * * @return string The name of the class to instantiate. - * + * @todo Can be optimized performance-wise. */ protected function _getClassnameToReturn(array $data, $className) { - $subClasses = $this->_mappers[$className]->getTable()->getOption('subclasses'); - if ( ! isset($subClasses)) { + if ( ! isset($this->_mappers[$className])) { + $this->_mappers[$className] = Doctrine_Manager::getInstance()->getMapper($className); + } + + $discCol = $this->_mappers[$className]->getTable()->getInheritanceOption('discriminatorColumn'); + if ( ! $discCol) { return $className; } - - foreach ($subClasses as $subclass) { - if ( ! isset($this->_mappers[$subclass])) { - $this->_mappers[$subclass] = Doctrine_Manager::getInstance()->getMapper($subclass); - } - $mapper = $this->_mappers[$subclass]; - $inheritanceMap = $mapper->getDiscriminatorColumn(); - foreach ($inheritanceMap as $key => $value) { - if (isset($data[$key]) && $data[$key] == $value) { - return $mapper->getComponentName(); - } + + $discMap = $this->_mappers[$className]->getTable()->getInheritanceOption('discriminatorMap'); + foreach ($discMap as $value => $class) { + if (isset($data[$discCol]) && $data[$discCol] == $value) { + return $class; } } + return $className; } } diff --git a/lib/Doctrine/Manager.php b/lib/Doctrine/Manager.php index 2b178e65c..9c9b1c3c3 100644 --- a/lib/Doctrine/Manager.php +++ b/lib/Doctrine/Manager.php @@ -64,6 +64,9 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera */ protected $_queryRegistry; + /** + * + */ protected static $driverMap = array('oci' => 'oracle'); /** @@ -476,6 +479,32 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera return $this->_connections[$name]; } + + /** + * Creates a new Doctrine_Query object that uses the currently active connection. + * + * @return Doctrine_Query + */ + public function createQuery($dql = "") + { + $query = new Doctrine_Query($this->getCurrentConnection()); + if ( ! empty($dql)) { + $query->parseQuery($dql); + } + + return $query; + } + + /** + * Creates a query object out of a registered, named query. + * + * @param string $name The name of the query. + * @return Doctrine_Query The query object. + */ + public function createNamedQuery($name) + { + return $this->_queryRegistry->get($name); + } /** * getComponentAlias diff --git a/lib/Doctrine/Mapper/Abstract.php b/lib/Doctrine/Mapper/Abstract.php index 53301fd2e..9de1aa40f 100644 --- a/lib/Doctrine/Mapper/Abstract.php +++ b/lib/Doctrine/Mapper/Abstract.php @@ -31,14 +31,13 @@ * @link www.phpdoctrine.org * @since 1.0 */ -abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable - implements Countable +abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable implements Countable { /** * @var Doctrine_Table Metadata container that represents the database table this * mapper is mapping objects to. */ - protected $_table; + protected $_classMetadata; /** * The name of the domain class this mapper is used for. @@ -82,11 +81,11 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable * @param Doctrine_Table $table The table object used for the mapping procedure. * @throws Doctrine_Connection_Exception if there are no opened connections */ - public function __construct($name, Doctrine_Table $table) + public function __construct($name, Doctrine_ClassMetadata $metadata) { $this->_domainClassName = $name; - $this->_conn = $table->getConnection(); - $this->_table = $table; + $this->_conn = $metadata->getConnection(); + $this->_classMetadata = $metadata; $this->setParent($this->_conn); $this->_repository = new Doctrine_Table_Repository($this); } @@ -110,11 +109,13 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable * occurred during the create table operation * @return boolean whether or not the export operation was successful * false if table already existed in the database + * @deprecated + * @todo Remove */ - public function export() + /*public function export() { $this->_conn->export->exportTable($this->_table); - } + }*/ /** * getExportableFormat @@ -123,10 +124,10 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable * @return array * @todo move to Table */ - public function getExportableFormat($parseForeignKeys = true) + /*public function getExportableFormat($parseForeignKeys = true) { return $this->_table->getExportableFormat($parseForeignKeys); - } + }*/ /** * createQuery @@ -169,9 +170,9 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable } /** - * returns the connection associated with this table (if any) + * Returns the connection the mapper is currently using. * - * @return Doctrine_Connection|null the connection object + * @return Doctrine_Connection|null The connection object. */ public function getConnection() { @@ -207,8 +208,9 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable } $id = is_array($id) ? array_values($id) : array($id); + return $this->createQuery() - ->where(implode(' = ? AND ', (array) $this->_table->getIdentifier()) . ' = ?') + ->where(implode(' = ? AND ', (array) $this->_classMetadata->getIdentifier()) . ' = ?') ->fetchOne($id, $hydrationMode); } @@ -324,7 +326,7 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable * * @param Doctrine_Record $record record to be added * @return boolean - * @todo Better name? registerRecord? + * @todo Better name? registerRecord? Move elsewhere to the new location of the identity maps. */ public function addRecord(Doctrine_Record $record) { @@ -346,6 +348,7 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable * * @param Doctrine_Record $record record to be removed * @return boolean + * @todo Move elsewhere to the new location of the identity maps. */ public function removeRecord(Doctrine_Record $record) { @@ -369,7 +372,7 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable public function getRecord(array $data) { if ( ! empty($data)) { - $identifierFieldNames = $this->_table->getIdentifier(); + $identifierFieldNames = $this->_classMetadata->getIdentifier(); if ( ! is_array($identifierFieldNames)) { $identifierFieldNames = array($identifierFieldNames); @@ -386,8 +389,6 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable } if ($found) { - //$recordName = $this->getClassnameToReturn(); - //$record = new $recordName($this, true); $record = new $this->_domainClassName($this, true, $data); $data = array(); return $record; @@ -400,61 +401,17 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable $record = $this->_identityMap[$id]; $record->hydrate($data); } else { - //$recordName = $this->getClassnameToReturn(); - //$record = new $recordName($this); $record = new $this->_domainClassName($this, false, $data); $this->_identityMap[$id] = $record; } $data = array(); } else { - //$recordName = $this->getClassnameToReturn(); - //$record = new $recordName($this, true); $record = new $this->_domainClassName($this, true, $data); } return $record; } - /** - * Get the classname to return. Most often this is just the options['name'] - * - * USED FOR SINGLE TABLE INHERITANCE & CLASS TABLE INHERITANCE. - * - * Check the subclasses option and the inheritanceMap for each subclass to see - * if all the maps in a subclass is met. If this is the case return that - * subclass name. If no subclasses match or if there are no subclasses defined - * return the name of the class for this tables record. - * - * @todo this function could use reflection to check the first time it runs - * if the subclassing option is not set. - * - * @return string The name of the class to create - * - */ - /*public function getClassnameToReturn() - { - $subClasses = $this->_table->getOption('subclasses'); - if ( ! isset($subClasses)) { - return $this->_domainClassName; - } - - foreach ($subClasses as $subclass) { - $mapper = $this->_conn->getMapper($subclass); - $nomatch = false; - $inheritanceMap = $this->getDiscriminatorColumn($subclass); - foreach ($inheritanceMap as $key => $value) { - if ( ! isset($this->_data[$key]) || $this->_data[$key] != $value) { - $nomatch = true; - break; - } - } - if ( ! $nomatch) { - return $mapper->getComponentName(); - } - } - return $this->_domainClassName; - }*/ - /** * @param $id database row id * @throws Doctrine_Find_Exception @@ -462,9 +419,9 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable final public function getProxy($id = null) { if ($id !== null) { - $identifierColumnNames = $this->_table->getIdentifierColumnNames(); + $identifierColumnNames = $this->_classMetadata->getIdentifierColumnNames(); $query = 'SELECT ' . implode(', ', $identifierColumnNames) - . ' FROM ' . $this->_table->getTableName() + . ' FROM ' . $this->_classMetadata->getTableName() . ' WHERE ' . implode(' = ? && ', $identifierColumnNames) . ' = ?'; $query = $this->applyInheritance($query); @@ -476,6 +433,7 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable return false; } } + return $this->getRecord($data); } @@ -486,15 +444,22 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable */ final public function applyInheritance($where) { - $inheritanceMap = $this->getDiscriminatorColumn(); + $discCol = $this->_classMetadata->getInheritanceOption('discriminatorColumn'); + if ( ! $discCol) { + return $where; + } + + $discMap = $this->_classMetadata->getInheritanceOption('discriminatorMap'); + $inheritanceMap = array($discCol => array_search($this->_domainClassName, $discMap)); if ( ! empty($inheritanceMap)) { $a = array(); - foreach ($inheritanceMap as $field => $value) { - $a[] = $this->_table->getColumnName($field) . ' = ?'; + foreach ($inheritanceMap as $column => $value) { + $a[] = $column . ' = ?'; } $i = implode(' AND ', $a); $where .= ' AND ' . $i; } + return $where; } @@ -505,7 +470,7 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable */ public function count() { - $a = $this->_conn->execute('SELECT COUNT(1) FROM ' . $this->_table->getOption('tableName'))->fetch(Doctrine::FETCH_NUM); + $a = $this->_conn->execute('SELECT COUNT(1) FROM ' . $this->_classMetadata->getOption('tableName'))->fetch(Doctrine::FETCH_NUM); return current($a); } @@ -549,7 +514,7 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable } else if ($value === null) { return null; } else { - $type = $this->_table->getTypeOf($fieldName); + $type = $this->_classMetadata->getTypeOf($fieldName); switch ($type) { case 'integer': @@ -557,7 +522,7 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable // don't do any casting here PHP INT_MAX is smaller than what the databases support break; case 'enum': - return $this->_table->enumValue($fieldName, $value); + return $this->_classMetadata->enumValue($fieldName, $value); break; case 'boolean': return (boolean) $value; @@ -590,10 +555,11 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable * getter for associated tree * * @return mixed if tree return instance of Doctrine_Tree, otherwise returns false + * @todo Part of the NestedSet Behavior plugin. Move outta here some day... */ public function getTree() { - return $this->_table->getTree(); + return $this->_classMetadata->getTree(); } /** @@ -602,10 +568,11 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable * determine if table acts as tree * * @return mixed if tree return true, otherwise returns false + * @todo Part of the NestedSet Behavior plugin. Move outta here some day... */ public function isTree() { - return $this->_table->isTree(); + return $this->_classMetadata->isTree(); } /** @@ -673,20 +640,22 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable } else if (substr($method, 0, 9) == 'findOneBy') { $by = substr($method, 9, strlen($method)); $method = 'findOneBy'; - } + }/* else { + throw new Doctrine_Mapper_Exception("Unknown method '$method'."); + }*/ if (isset($by)) { if ( ! isset($arguments[0])) { - throw new Doctrine_Table_Exception('You must specify the value to findBy'); + throw new Doctrine_Mapper_Exception('You must specify the value to findBy'); } $fieldName = Doctrine::tableize($by); $hydrationMode = isset($arguments[1]) ? $arguments[1]:null; - if ($this->_table->hasField($fieldName)) { + if ($this->_classMetadata->hasField($fieldName)) { return $this->$method($fieldName, $arguments[0], $hydrationMode); - } else if ($this->_table->hasRelation($by)) { - $relation = $this->_table->getRelation($by); + } else if ($this->_classMetadata->hasRelation($by)) { + $relation = $this->_classMetadata->getRelation($by); if ($relation['type'] === Doctrine_Relation::MANY) { throw new Doctrine_Table_Exception('Cannot findBy many relationship.'); @@ -727,7 +696,7 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable try { $conn->beginInternalTransaction(); - $saveLater = $this->saveRelated($record); + $saveLater = $this->_saveRelated($record); //echo "num savelater:" . count($saveLater) . "
"; $record->state($state); @@ -814,13 +783,12 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable $fields[$seqName] = $id; $record->assignIdentifier($id); } - + $this->_conn->insert($table, $fields); if (empty($seq) && count($identifier) == 1 && $identifier[0] == $table->getIdentifier() && $table->getIdentifierType() != Doctrine::IDENTIFIER_NATURAL) { - - if (strtolower($this->getName()) == 'pgsql') { + if (strtolower($this->_conn->getName()) == 'pgsql') { $seq = $table->getTableName() . '_' . $identifier[0]; } @@ -874,16 +842,14 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable $record->postSave($event); } - - /** - * saveRelated + * _saveRelated * saves all related records to $record * * @throws PDOException if something went wrong at database level * @param Doctrine_Record $record */ - protected function saveRelated(Doctrine_Record $record) + protected function _saveRelated(Doctrine_Record $record) { $saveLater = array(); foreach ($record->getReferences() as $k => $v) { @@ -934,12 +900,13 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable public function saveAssociations(Doctrine_Record $record) { foreach ($record->getReferences() as $relationName => $relatedObject) { + $rel = $record->getTable()->getRelation($relationName); - if ($rel instanceof Doctrine_Relation_Association) { + if ($rel instanceof Doctrine_Relation_Association) { $relatedObject->save($this->_conn); - $assocTable = $rel->getAssociationTable(); + foreach ($relatedObject->getDeleteDiff() as $r) { $query = 'DELETE FROM ' . $assocTable->getTableName() . ' WHERE ' . $rel->getForeign() . ' = ?' @@ -947,7 +914,7 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable $this->_conn->execute($query, array($r->getIncremented(), $record->getIncremented())); } - foreach ($relatedObject->getInsertDiff() as $r) { + foreach ($relatedObject->getInsertDiff() as $r) { $assocRecord = $this->_conn->getMapper($assocTable->getComponentName())->create(); $assocRecord->set($assocTable->getFieldName($rel->getForeign()), $r); $assocRecord->set($assocTable->getFieldName($rel->getLocal()), $record); @@ -969,7 +936,7 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable { $event = new Doctrine_Event($record, Doctrine_Event::RECORD_UPDATE); $record->preUpdate($event); - $table = $this->_table; + $table = $this->_classMetadata; $this->getRecordListener()->preUpdate($event); if ( ! $event->skipOperation) { @@ -986,7 +953,7 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable { $identifier = $record->identifier(); $array = $record->getPrepared(); - $this->_conn->update($this->_table, $array, $identifier); + $this->_conn->update($this->_classMetadata, $array, $identifier); $record->assignIdentifier(true); } @@ -1048,7 +1015,7 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable $record->preDelete($event); $this->getRecordListener()->preDelete($event); - $table = $this->_table; + $table = $this->_classMetadata; $state = $record->state(); $record->state(Doctrine_Record::STATE_LOCKED); @@ -1074,7 +1041,7 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable $record->state(Doctrine_Record::STATE_TDIRTY); - $conn->delete($this->_table, $record->identifier()); + $conn->delete($this->_classMetadata, $record->identifier()); $record->state(Doctrine_Record::STATE_TCLEAN); $this->removeRecord($record); @@ -1095,7 +1062,7 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable */ protected function deleteComposites(Doctrine_Record $record) { - foreach ($this->_table->getRelations() as $fk) { + foreach ($this->_classMetadata->getRelations() as $fk) { if ($fk->isComposite()) { $obj = $record->get($fk->getAlias()); if ($obj instanceof Doctrine_Record && @@ -1113,12 +1080,12 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable public function getTable() { - return $this->_table; + return $this->_classMetadata; } public function getFieldName($columnName) { - return $this->_table->getFieldName($columnName); + return $this->_classMetadata->getFieldName($columnName); } public function getFieldNames() @@ -1126,13 +1093,13 @@ abstract class Doctrine_Mapper_Abstract extends Doctrine_Configurable if ($this->_fieldNames) { return $this->_fieldNames; } - $this->_fieldNames = $this->_table->getFieldNames(); + $this->_fieldNames = $this->_classMetadata->getFieldNames(); return $this->_fieldNames; } public function getOwningTable($fieldName) { - return $this->_table; + return $this->_classMetadata; } public function getIdentityMap() diff --git a/lib/Doctrine/Mapper/Joined.php b/lib/Doctrine/Mapper/Joined.php index 06a03799e..311e48465 100644 --- a/lib/Doctrine/Mapper/Joined.php +++ b/lib/Doctrine/Mapper/Joined.php @@ -13,19 +13,19 @@ class Doctrine_Mapper_Joined extends Doctrine_Mapper_Abstract */ protected function _doInsert(Doctrine_Record $record) { - $table = $this->_table; + $table = $this->_classMetadata; $dataSet = $this->_formatDataSet($record); - $component = $table->getComponentName(); + $component = $table->getClassName(); - $classes = $table->getOption('joinedParents'); + $classes = $table->getOption('parents'); array_unshift($classes, $component); try { $this->_conn->beginInternalTransaction(); $identifier = null; foreach (array_reverse($classes) as $k => $parent) { - $parentTable = $this->_conn->getTable($parent); + $parentTable = $this->_conn->getMetadata($parent); if ($k == 0) { $identifierType = $parentTable->getIdentifierType(); if ($identifierType == Doctrine::IDENTIFIER_AUTOINC) { @@ -67,11 +67,11 @@ class Doctrine_Mapper_Joined extends Doctrine_Mapper_Abstract */ protected function _doUpdate(Doctrine_Record $record) { - $table = $this->_table; + $table = $this->_classMetadata; $identifier = $record->identifier(); $dataSet = $this->_formatDataSet($record); - $component = $table->getComponentName(); - $classes = $table->getOption('joinedParents'); + $component = $table->getClassName(); + $classes = $table->getOption('parents'); array_unshift($classes, $component); foreach ($record as $field => $value) { @@ -84,7 +84,7 @@ class Doctrine_Mapper_Joined extends Doctrine_Mapper_Abstract } foreach (array_reverse($classes) as $class) { - $parentTable = $this->_conn->getTable($class); + $parentTable = $this->_conn->getMetadata($class); $this->_conn->update($parentTable, $dataSet[$class], $identifier); } @@ -97,7 +97,7 @@ class Doctrine_Mapper_Joined extends Doctrine_Mapper_Abstract protected function _doDelete(Doctrine_Record $record, Doctrine_Connection $conn) { try { - $table = $this->_table; + $table = $this->_classMetadata; $conn->beginInternalTransaction(); $this->deleteComposites($record); @@ -128,10 +128,10 @@ class Doctrine_Mapper_Joined extends Doctrine_Mapper_Abstract public function getCustomJoins() { $customJoins = array(); - foreach ($this->_table->getOption('joinedParents') as $parentClass) { + foreach ($this->_classMetadata->getOption('parents') as $parentClass) { $customJoins[$parentClass] = 'INNER'; } - foreach ((array)$this->_table->getOption('subclasses') as $subClass) { + foreach ((array)$this->_classMetadata->getOption('subclasses') as $subClass) { if ($subClass != $this->_domainClassName) { $customJoins[$subClass] = 'LEFT'; } @@ -141,10 +141,11 @@ class Doctrine_Mapper_Joined extends Doctrine_Mapper_Abstract public function getCustomFields() { - $fields = array(); - if ($this->_table->getOption('subclasses')) { - foreach ($this->_table->getOption('subclasses') as $subClass) { - $fields = array_merge($this->_conn->getTable($subClass)->getFieldNames(), $fields); + $fields = array($this->_classMetadata->getInheritanceOption('discriminatorColumn')); + //$fields = array(); + if ($this->_classMetadata->getOption('subclasses')) { + foreach ($this->_classMetadata->getOption('subclasses') as $subClass) { + $fields = array_merge($this->_conn->getMetadata($subClass)->getFieldNames(), $fields); } } return array_unique($fields); @@ -155,9 +156,9 @@ class Doctrine_Mapper_Joined extends Doctrine_Mapper_Abstract */ public function getDiscriminatorColumn() { - $joinedParents = $this->_table->getOption('joinedParents'); + $joinedParents = $this->_classMetadata->getOption('joinedParents'); if (count($joinedParents) <= 0) { - $inheritanceMap = $this->_table->getOption('inheritanceMap'); + $inheritanceMap = $this->_classMetadata->getOption('inheritanceMap'); } else { $inheritanceMap = $this->_conn->getTable(array_pop($joinedParents))->getOption('inheritanceMap'); } @@ -173,11 +174,7 @@ class Doctrine_Mapper_Joined extends Doctrine_Mapper_Abstract return $this->_fieldNames; } - $fieldNames = $this->_table->getFieldNames(); - foreach ($this->_table->getOption('joinedParents') as $parent) { - $parentTable = $this->_conn->getTable($parent); - $fieldNames = array_merge($parentTable->getFieldNames(), $fieldNames); - } + $fieldNames = $this->_classMetadata->getFieldNames(); $this->_fieldNames = array_unique($fieldNames); return $fieldNames; @@ -189,46 +186,46 @@ class Doctrine_Mapper_Joined extends Doctrine_Mapper_Abstract return $this->_columnNameFieldNameMap[$columnName]; } - if ($this->_table->hasColumn($columnName)) { - $this->_columnNameFieldNameMap[$columnName] = $this->_table->getFieldName($columnName); + if ($this->_classMetadata->hasColumn($columnName)) { + $this->_columnNameFieldNameMap[$columnName] = $this->_classMetadata->getFieldName($columnName); return $this->_columnNameFieldNameMap[$columnName]; } - foreach ($this->_table->getOption('joinedParents') as $parentClass) { - $parentTable = $this->_conn->getTable($parentClass); + foreach ($this->_classMetadata->getOption('parents') as $parentClass) { + $parentTable = $this->_conn->getMetadata($parentClass); if ($parentTable->hasColumn($columnName)) { $this->_columnNameFieldNameMap[$columnName] = $parentTable->getFieldName($columnName); return $this->_columnNameFieldNameMap[$columnName]; } } - foreach ((array)$this->_table->getOption('subclasses') as $subClass) { - $subTable = $this->_conn->getTable($subClass); + foreach ((array)$this->_classMetadata->getOption('subclasses') as $subClass) { + $subTable = $this->_conn->getMetadata($subClass); if ($subTable->hasColumn($columnName)) { $this->_columnNameFieldNameMap[$columnName] = $subTable->getFieldName($columnName); return $this->_columnNameFieldNameMap[$columnName]; } } - + throw new Doctrine_Mapper_Exception("No field name found for column name '$columnName'."); } public function getOwningTable($fieldName) - { - if ($this->_table->hasField($fieldName)) { - return $this->_table; + { + if ($this->_classMetadata->hasField($fieldName) && ! $this->_classMetadata->isInheritedField($fieldName)) { + return $this->_classMetadata; } - foreach ($this->_table->getOption('joinedParents') as $parentClass) { - $parentTable = $this->_conn->getTable($parentClass); - if ($parentTable->hasField($fieldName)) { + foreach ($this->_classMetadata->getOption('parents') as $parentClass) { + $parentTable = $this->_conn->getMetadata($parentClass); + if ($parentTable->hasField($fieldName) && ! $parentTable->isInheritedField($fieldName)) { return $parentTable; } } - foreach ((array)$this->_table->getOption('subclasses') as $subClass) { - $subTable = $this->_conn->getTable($subClass); - if ($subTable->hasField($fieldName)) { + foreach ((array)$this->_classMetadata->getOption('subclasses') as $subClass) { + $subTable = $this->_conn->getMetadata($subClass); + if ($subTable->hasField($fieldName) && ! $subTable->isInheritedField($fieldName)) { return $subTable; } } @@ -241,17 +238,18 @@ class Doctrine_Mapper_Joined extends Doctrine_Mapper_Abstract */ protected function _formatDataSet(Doctrine_Record $record) { - $table = $this->_table; + $table = $this->_classMetadata; $dataSet = array(); - $component = $table->getComponentName(); + $component = $table->getClassName(); $array = $record->getPrepared(); - $classes = array_merge(array($component), $this->_table->getOption('joinedParents')); + $classes = array_merge(array($component), $this->_classMetadata->getParentClasses()); foreach ($classes as $class) { - $table = $this->_conn->getTable($class); - foreach ($table->getColumns() as $columnName => $definition) { - if (isset($definition['primary'])) { + $metadata = $this->_conn->getMetadata($class); + foreach ($metadata->getColumns() as $columnName => $definition) { + if ((isset($definition['primary']) && $definition['primary'] === true) || + (isset($definition['inherited']) && $definition['inherited'] === true)) { continue; } $fieldName = $table->getFieldName($columnName); diff --git a/lib/Doctrine/Mapper/SingleTable.php b/lib/Doctrine/Mapper/SingleTable.php index 5ab32d4b6..2808ce12a 100644 --- a/lib/Doctrine/Mapper/SingleTable.php +++ b/lib/Doctrine/Mapper/SingleTable.php @@ -5,7 +5,7 @@ class Doctrine_Mapper_SingleTable extends Doctrine_Mapper_Abstract public function getDiscriminatorColumn() { - $inheritanceMap = $this->_table->getOption('inheritanceMap'); + $inheritanceMap = $this->_classMetadata->getOption('inheritanceMap'); return isset($inheritanceMap[$this->_domainClassName]) ? $inheritanceMap[$this->_domainClassName] : array(); } diff --git a/lib/Doctrine/Node/NestedSet.php b/lib/Doctrine/Node/NestedSet.php index 75884cfa9..bd4ecd868 100644 --- a/lib/Doctrine/Node/NestedSet.php +++ b/lib/Doctrine/Node/NestedSet.php @@ -302,8 +302,10 @@ class Doctrine_Node_NestedSet extends Doctrine_Node implements Doctrine_Node_Int { $path = array(); $ancestors = $this->getAncestors(); - foreach ($ancestors as $ancestor) { - $path[] = $ancestor->__toString(); + if ($ancestors) { + foreach ($ancestors as $ancestor) { + $path[] = $ancestor->__toString(); + } } if ($includeRecord) { $path[] = $this->getRecord()->__toString(); diff --git a/lib/Doctrine/Query.php b/lib/Doctrine/Query.php index 819f915ac..122bcb385 100644 --- a/lib/Doctrine/Query.php +++ b/lib/Doctrine/Query.php @@ -1620,7 +1620,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria $this->_conn = $manager->getConnectionForComponent($name); } - $table = $this->_conn->getTable($name); + $table = $this->_conn->getMetadata($name); $tableName = $table->getTableName(); // get the short alias for this table diff --git a/lib/Doctrine/Query/Abstract.php b/lib/Doctrine/Query/Abstract.php index b8217ef0a..9993e74bf 100644 --- a/lib/Doctrine/Query/Abstract.php +++ b/lib/Doctrine/Query/Abstract.php @@ -528,12 +528,12 @@ abstract class Doctrine_Query_Abstract */ protected function _createCustomJoinSql($componentName, $componentAlias) { - $table = $this->_conn->getTable($componentName); + $table = $this->_conn->getMetadata($componentName); $tableAlias = $this->getSqlTableAlias($componentAlias, $table->getTableName()); $customJoins = $this->_conn->getMapper($componentName)->getCustomJoins(); $sql = ''; foreach ($customJoins as $componentName => $joinType) { - $joinedTable = $this->_conn->getTable($componentName); + $joinedTable = $this->_conn->getMetadata($componentName); $joinedAlias = $componentAlias . '.' . $componentName; $joinedTableAlias = $this->getSqlTableAlias($joinedAlias, $joinedTable->getTableName()); $sql .= " $joinType JOIN " . $this->_conn->quoteIdentifier($joinedTable->getTableName()) @@ -553,6 +553,7 @@ abstract class Doctrine_Query_Abstract /** * Creates the SQL snippet for the WHERE part that contains the discriminator * column conditions. + * Used solely for Single Table Inheritance. * * @return string The created SQL snippet. */ @@ -564,7 +565,25 @@ abstract class Doctrine_Query_Abstract if ( ! $data['mapper'] instanceof Doctrine_Mapper_SingleTable) { $array[$sqlTableAlias][] = array(); } else { - $array[$sqlTableAlias][] = $data['mapper']->getDiscriminatorColumn(); + $discCol = $data['table']->getInheritanceOption('discriminatorColumn'); + $discMap = $data['table']->getInheritanceOption('discriminatorMap'); + $discValue = array_search($data['table']->getClassName(), $discMap); + if ($discValue === false) { + continue; + } + $discriminator = array(); + $discriminator[] = array($discCol => $discValue); + + $subclasses = $data['table']->getSubclasses(); + foreach ((array)$subclasses as $subclass) { + $subClassMetadata = $this->_conn->getClassMetadata($subclass); + $discCol = $subClassMetadata->getInheritanceOption('discriminatorColumn'); + $discMap = $subClassMetadata->getInheritanceOption('discriminatorMap'); + $discValue = array_search($subclass, $discMap); + $discriminator[] = array($discCol => $discValue); + } + + $array[$sqlTableAlias][] = $discriminator; } } //var_dump($array); @@ -584,10 +603,11 @@ abstract class Doctrine_Query_Abstract } foreach ($maps as $map) { + //echo "start"; $b = array(); - foreach ($map as $field => $value) { - $identifier = $this->_conn->quoteIdentifier($tableAlias . $field); - + foreach ($map as $discriminator) { + list($column, $value) = each($discriminator); + $identifier = $this->_conn->quoteIdentifier($tableAlias . $column); if ($index > 0) { $b[] = '(' . $identifier . ' = ' . $this->_conn->quote($value) . ' OR ' . $identifier . ' IS NULL)'; @@ -597,10 +617,14 @@ abstract class Doctrine_Query_Abstract } if ( ! empty($b)) { - $a[] = implode(' AND ', $b); + if (count($b) > 1) { + $a[] = '(' . implode(' OR ', $b) . ')'; + } else { + $a[] = implode(' OR ', $b); + } } } - + //echo "end
"; if ( ! empty($a)) { $c[] = implode(' AND ', $a); } diff --git a/lib/Doctrine/Query/Check.php b/lib/Doctrine/Query/Check.php index 4fc149309..0db12fc7f 100644 --- a/lib/Doctrine/Query/Check.php +++ b/lib/Doctrine/Query/Check.php @@ -53,7 +53,7 @@ class Doctrine_Query_Check if ( ! ($table instanceof Doctrine_Table)) { $table = Doctrine_Manager::getInstance() ->getCurrentConnection() - ->getTable($table); + ->getClassMetadata($table); } $this->table = $table; $this->_tokenizer = new Doctrine_Query_Tokenizer(); diff --git a/lib/Doctrine/Query/Where.php b/lib/Doctrine/Query/Where.php index 7ecd87162..95c0c42fb 100644 --- a/lib/Doctrine/Query/Where.php +++ b/lib/Doctrine/Query/Where.php @@ -86,7 +86,7 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition } } - public function parseValue($value, Doctrine_Table $table = null, $field = null) + public function parseValue($value, $table = null, $field = null) { $conn = $this->query->getConnection(); diff --git a/lib/Doctrine/RawSql.php b/lib/Doctrine/RawSql.php index b384f344d..249af9577 100644 --- a/lib/Doctrine/RawSql.php +++ b/lib/Doctrine/RawSql.php @@ -81,6 +81,7 @@ class Doctrine_RawSql extends Doctrine_Query_Abstract } else { $this->_sqlParts[$queryPartName][] = $queryPart; } + return $this; } @@ -316,7 +317,7 @@ class Doctrine_RawSql extends Doctrine_Query_Abstract $conn = Doctrine_Manager::getInstance() ->getConnectionForComponent($component); - $table = $conn->getTable($component); + $table = $conn->getClassMetadata($component); $this->_queryComponents[$componentAlias] = array( 'table' => $table, 'mapper' => $conn->getMapper($component)); } else { @@ -324,7 +325,7 @@ class Doctrine_RawSql extends Doctrine_Query_Abstract $this->_queryComponents[$componentAlias] = array( 'table' => $relation->getTable(), - 'mapper' => $this->_conn->getMapper($component), + 'mapper' => $this->_conn->getMapper($component), 'parent' => $parent, 'relation' => $relation); } diff --git a/lib/Doctrine/Record.php b/lib/Doctrine/Record.php index 2c9081b17..de7919170 100644 --- a/lib/Doctrine/Record.php +++ b/lib/Doctrine/Record.php @@ -26,6 +26,7 @@ Doctrine::autoload('Doctrine_Record_Abstract'); * @package Doctrine * @subpackage Record * @author Konsta Vesterinen + * @author Roman Borschel * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @link www.phpdoctrine.com * @since 1.0 @@ -41,33 +42,33 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count * DIRTY STATE * a Doctrine_Record is in dirty state when its properties are changed */ - const STATE_DIRTY = 1; + const STATE_DIRTY = 1; /** * TDIRTY STATE * a Doctrine_Record is in transient dirty state when it is created * and some of its fields are modified but it is NOT yet persisted into database */ - const STATE_TDIRTY = 2; + const STATE_TDIRTY = 2; /** * CLEAN STATE * a Doctrine_Record is in clean state when all of its properties are loaded from the database * and none of its properties are changed */ - const STATE_CLEAN = 3; + const STATE_CLEAN = 3; /** * PROXY STATE * a Doctrine_Record is in proxy state when its properties are not fully loaded */ - const STATE_PROXY = 4; + const STATE_PROXY = 4; /** * NEW TCLEAN * a Doctrine_Record is in transient clean state when it is created and none of its fields are modified */ - const STATE_TCLEAN = 5; + const STATE_TCLEAN = 5; /** * LOCKED STATE @@ -76,7 +77,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count * This state is used internally to ensure that circular deletes * and saves will not cause infinite loops */ - const STATE_LOCKED = 6; + const STATE_LOCKED = 6; /** * @@ -85,58 +86,78 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count /** * @var Doctrine_Node_ node object + * @todo Specific to the NestedSet Behavior plugin. Move outta here. */ protected $_node; /** - * @var integer $_id the primary keys of this object + * The values that make up the ID/primary key of the object. + * + * @var array */ - protected $_id = array(); + protected $_id = array(); /** - * @var array $_data the record data + * The record data. + * + * @var array */ - protected $_data = array(); + protected $_data = array(); /** - * @var array $_values the values array, aggregate values and such are mapped into this array + * The values array, aggregate values and such are mapped into this array. + * + * @var array */ - protected $_values = array(); + protected $_values = array(); /** - * @var integer $_state the state of this record + * The state of the object. + * + * @var integer * @see STATE_* constants */ protected $_state; /** - * @var array $_modified an array containing field names that have been modified + * The names of fields that have been modified but not yet persisted. + * + * @var array * @todo Better name? $_modifiedFields? */ - protected $_modified = array(); + protected $_modified = array(); /** - * @var Doctrine_Validator_ErrorStack error stack object + * The error stack used to collect errors during validation. + * + * @var Doctrine_Validator_ErrorStack */ protected $_errorStack; /** - * @var array $_references an array containing all the references + * The names of all relations. + * + * @var array $_references */ - protected $_references = array(); + protected $_references = array(); /** - * @var integer $index this index is used for creating object identifiers + * Index used for creating object identifiers (oid's). + * + * @var integer $index */ private static $_index = 1; /** - * @var integer $oid object identifier, each Record object has a unique object identifier + * The object identifier of the object. Each object has a unique identifier during runtime. + * + * @var integer $oid */ private $_oid; /** - * constructor + * Constructor. + * * @param Doctrine_Table|null $table a Doctrine_Table object or null, * if null the table object is retrieved from current connection * @@ -148,21 +169,12 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count */ public function __construct($mapper = null, $isNewEntry = false, array $data = array()) { - //echo get_class($this) . "
"; - if (isset($mapper) && $mapper instanceof Doctrine_Table) { - //echo "one
"; - $this->_table = $mapper; - //$this->_mapper = Doctrine_Manager::getInstance()->getMapper(get_class($this)); - $exists = ! $isNewEntry; - return; - } else if (isset($mapper) && $mapper instanceof Doctrine_Mapper_Abstract) { - //echo "two
"; + if (isset($mapper) && $mapper instanceof Doctrine_Mapper_Abstract) { $class = get_class($this); $this->_mapper = Doctrine_Manager::getInstance()->getMapper($class); $this->_table = $this->_mapper->getTable(); $exists = ! $isNewEntry; } else { - //echo "three
"; $this->_mapper = Doctrine_Manager::getInstance()->getMapper(get_class($this)); $this->_table = $this->_mapper->getTable(); $exists = false; @@ -302,56 +314,56 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count * Empty template method to provide concrete Record classes with the possibility * to hook into the serializing procedure. */ - public function preSerialize($event) + public function preSerialize(Doctrine_Event $event) { } /** * Empty template method to provide concrete Record classes with the possibility * to hook into the serializing procedure. */ - public function postSerialize($event) + public function postSerialize(Doctrine_Event $event) { } /** * Empty template method to provide concrete Record classes with the possibility * to hook into the serializing procedure. */ - public function preUnserialize($event) + public function preUnserialize(Doctrine_Event $event) { } /** * Empty template method to provide concrete Record classes with the possibility * to hook into the serializing procedure. */ - public function postUnserialize($event) + public function postUnserialize(Doctrine_Event $event) { } /** * Empty template method to provide concrete Record classes with the possibility * to hook into the saving procedure. */ - public function preSave($event) + public function preSave(Doctrine_Event $event) { } /** * Empty template method to provide concrete Record classes with the possibility * to hook into the saving procedure. */ - public function postSave($event) + public function postSave(Doctrine_Event $event) { } /** * Empty template method to provide concrete Record classes with the possibility * to hook into the deletion procedure. */ - public function preDelete($event) + public function preDelete(Doctrine_Event $event) { } /** * Empty template method to provide concrete Record classes with the possibility * to hook into the deletion procedure. */ - public function postDelete($event) + public function postDelete(Doctrine_Event $event) { } /** @@ -359,7 +371,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count * to hook into the saving procedure only when the record is going to be * updated. */ - public function preUpdate($event) + public function preUpdate(Doctrine_Event $event) { } /** @@ -367,7 +379,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count * to hook into the saving procedure only when the record is going to be * updated. */ - public function postUpdate($event) + public function postUpdate(Doctrine_Event $event) { } /** @@ -375,7 +387,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count * to hook into the saving procedure only when the record is going to be * inserted into the data store the first time. */ - public function preInsert($event) + public function preInsert(Doctrine_Event $event) { } /** @@ -383,7 +395,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count * to hook into the saving procedure only when the record is going to be * inserted into the data store the first time. */ - public function postInsert($event) + public function postInsert(Doctrine_Event $event) { } /** @@ -855,9 +867,11 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count $this->_references[$fieldName] = $rel->fetchRelatedFor($this); } return $this->_references[$fieldName]; - } catch (Doctrine_Table_Exception $e) { - //echo $e->getTraceAsString(); - //echo "

"; + } catch (Doctrine_Relation_Exception $e) { + //echo $this->_domainClassName . "
"; + //var_dump($this->_values); + echo $e->getTraceAsString(); + echo "

"; foreach ($this->_table->getFilters() as $filter) { if (($value = $filter->filterGet($this, $fieldName, $value)) !== null) { return $value; @@ -932,8 +946,17 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count } } else { try { + /*echo $this->_domainClassName; + var_dump($this->_data); + echo "

"; + try { + throw new Exception(); + } catch (Exception $e) { + echo $e->getTraceAsString() . "
"; + } + echo "

";*/ $this->_coreSetRelated($fieldName, $value); - } catch (Doctrine_Table_Exception $e) { + } catch (Doctrine_Relation_Exception $e) { foreach ($this->_table->getFilters() as $filter) { if (($value = $filter->filterSet($this, $fieldName, $value)) !== null) { return $value; @@ -1187,16 +1210,21 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count $a[$field] = $this->_data[$field]; } } - //$map = $this->_table->getOption('inheritanceMap'); - $map = $this->_mapper->getDiscriminatorColumn(); - foreach ($map as $k => $v) { - $old = $this->get($k, false); + + // @todo cleanup + if ($this->_table->getInheritanceType() == Doctrine::INHERITANCETYPE_JOINED || + $this->_table->getInheritanceType() == Doctrine::INHERITANCETYPE_SINGLE_TABLE) { + $discCol = $this->_table->getInheritanceOption('discriminatorColumn'); + $discMap = $this->_table->getInheritanceOption('discriminatorMap'); + $old = $this->get($discCol, false); + $v = array_search($this->_domainClassName, $discMap); if ((string) $old !== (string) $v || $old === null) { - $a[$k] = $v; - $this->_data[$k] = $v; + $a[$discCol] = $v; + $this->_data[$discCol] = $v; } } + return $a; } diff --git a/lib/Doctrine/Record/Abstract.php b/lib/Doctrine/Record/Abstract.php index f70715300..64fb76eef 100644 --- a/lib/Doctrine/Record/Abstract.php +++ b/lib/Doctrine/Record/Abstract.php @@ -42,16 +42,21 @@ abstract class Doctrine_Record_Abstract extends Doctrine_Access * @var Doctrine_Mapper_Abstract */ protected $_mapper; - - public function setTableDefinition() - { - - } + /** + * @deprecated + */ + public function setTableDefinition() + {} + + /** + * @deprecated + */ public function setUp() - { - - } + {} + + public static function initMapping(Doctrine_MetadataClass $class) + {} /** @@ -65,6 +70,9 @@ abstract class Doctrine_Record_Abstract extends Doctrine_Access return $this->_table; } + /** + * Returns the mapper of the entity. + */ public function getMapper() { return $this->_mapper; @@ -105,51 +113,12 @@ abstract class Doctrine_Record_Abstract extends Doctrine_Access return $this; } - - /** - * index - * defines or retrieves an index - * if the second parameter is set this method defines an index - * if not this method retrieves index named $name - * - * @param string $name the name of the index - * @param array $definition the definition array - * @return mixed - */ - public function index($name, array $definition = array()) - { - if ( ! $definition) { - return $this->_table->getIndex($name); - } else { - return $this->_table->addIndex($name, $definition); - } - } + public function setAttribute($attr, $value) { $this->_table->setAttribute($attr, $value); } - public function setTableName($tableName) - { - $this->_table->setTableName($tableName); - } - /** - * - * @deprecated Use setSubclasses() - */ - public function setInheritanceMap($map) - { - $this->_table->setOption('inheritanceMap', $map); - } - - public function setSubclasses($map) - { - //echo "setting inheritance map on " . get_class($this) . "
"; - $this->_table->setOption('inheritanceMap', $map); - $this->_table->setOption('subclasses', array_keys($map)); - $this->_table->setInheritanceType(Doctrine::INHERITANCETYPE_SINGLE_TABLE); - } - /** * attribute * sets or retrieves an option @@ -174,6 +143,50 @@ abstract class Doctrine_Record_Abstract extends Doctrine_Access } } + + /* THE FOLLOWING STUFF WILL ALL BE REMOVED SOON */ + + public function setTableName($tableName) + { + $this->_table->setTableName($tableName); + } + + /** + * index + * defines or retrieves an index + * if the second parameter is set this method defines an index + * if not this method retrieves index named $name + * + * @param string $name the name of the index + * @param array $definition the definition array + * @return mixed + */ + public function index($name, array $definition = array()) + { + if ( ! $definition) { + return $this->_table->getIndex($name); + } else { + return $this->_table->addIndex($name, $definition); + } + } + + /** + * + * @deprecated Use setSubclasses() + */ + public function setInheritanceMap($map) + { + $this->_table->setOption('inheritanceMap', $map); + } + + public function setSubclasses($map) + { + //echo "setting inheritance map on " . get_class($this) . "
"; + $this->_table->setOption('inheritanceMap', $map); + $this->_table->setOption('subclasses', array_keys($map)); + $this->_table->setInheritanceType(Doctrine::INHERITANCETYPE_SINGLE_TABLE); + } + /** * option * sets or retrieves an option @@ -282,7 +295,7 @@ abstract class Doctrine_Record_Abstract extends Doctrine_Access { $this->_table->setColumn($name, $type, $length, $options); } - + /** * hasColumns * @@ -389,11 +402,6 @@ abstract class Doctrine_Record_Abstract extends Doctrine_Access } $this->_table->setInheritanceType($type); } - - protected function _getMapper($className) - { - - } /** * check diff --git a/lib/Doctrine/Record/Filter.php b/lib/Doctrine/Record/Filter.php index e97fe0e35..35c51dfee 100644 --- a/lib/Doctrine/Record/Filter.php +++ b/lib/Doctrine/Record/Filter.php @@ -35,7 +35,7 @@ abstract class Doctrine_Record_Filter { protected $_table; - public function setTable(Doctrine_Table $table) + public function setTable(Doctrine_ClassMetadata $table) { $this->_table = $table; } diff --git a/lib/Doctrine/Record/Generator.php b/lib/Doctrine/Record/Generator.php index 310c989bc..4d34bbdf1 100644 --- a/lib/Doctrine/Record/Generator.php +++ b/lib/Doctrine/Record/Generator.php @@ -111,7 +111,7 @@ abstract class Doctrine_Record_Generator extends Doctrine_Record_Abstract return $this->_options; } - public function initialize(Doctrine_Table $table) + public function initialize($table) { if ($this->_initialized) { return false; @@ -188,7 +188,7 @@ abstract class Doctrine_Record_Generator extends Doctrine_Record_Abstract * @param Doctrine_Table $table the table object that owns the plugin * @return array an array of foreign key definitions */ - public function buildForeignKeys(Doctrine_Table $table) + public function buildForeignKeys($table) { $fk = array(); diff --git a/lib/Doctrine/Relation.php b/lib/Doctrine/Relation.php index 5987e86b6..5104a6bb5 100644 --- a/lib/Doctrine/Relation.php +++ b/lib/Doctrine/Relation.php @@ -143,6 +143,11 @@ abstract class Doctrine_Relation implements ArrayAccess $def = array(); foreach ($this->definition as $key => $val) { if ( ! isset($definition[$key]) && $val) { + try { + throw new Exception(); + } catch (Exception $e) { + echo $e->getTraceAsString() . "
"; + } throw new Doctrine_Exception($key . ' is required!'); } if (isset($definition[$key])) { @@ -257,7 +262,7 @@ abstract class Doctrine_Relation implements ArrayAccess { return Doctrine_Manager::getInstance() ->getConnectionForComponent($this->definition['class']) - ->getTable($this->definition['class']); + ->getMetadata($this->definition['class']); } /** diff --git a/lib/Doctrine/Relation/Association.php b/lib/Doctrine/Relation/Association.php index 851a2b8d1..bcce22e7a 100644 --- a/lib/Doctrine/Relation/Association.php +++ b/lib/Doctrine/Relation/Association.php @@ -61,19 +61,7 @@ class Doctrine_Relation_Association extends Doctrine_Relation public function getRelationDql($count, $context = 'record') { //$table = $this->definition['refTable']; - $assocRelationName = isset($this->definition['refReverseRelationName']) ? - $this->definition['refReverseRelationName'] : $this->definition['refClass']; - - /*if ($this->definition['localTable'] === $this->definition['table']) { - echo $this->definition['class']; - $rel = $this->definition['table']->getRelation('User'); - $relationName = $rel->getRelationName(); - }*/ - - //var_dump($this->definition['foreign']) . "
"; - //echo $component; - //$rel = $this->definition['refTable']->getRelation($this->_foreignMapper->getComponentName()); - //echo "LOCAL:" . $rel->getLocal() . "
"; + $assocRelationName = $this->definition['refClass']; $relatedClassName = $this->_foreignMapper->getComponentName(); diff --git a/lib/Doctrine/Relation/Parser.php b/lib/Doctrine/Relation/Parser.php index 6dfb8d46c..8b4d8b783 100644 --- a/lib/Doctrine/Relation/Parser.php +++ b/lib/Doctrine/Relation/Parser.php @@ -53,7 +53,7 @@ class Doctrine_Relation_Parser * * @param Doctrine_Table $table the table object this parser belongs to */ - public function __construct(Doctrine_Table $table) + public function __construct(/*Doctrine_Table*/ $table) { $this->_table = $table; } @@ -100,8 +100,8 @@ class Doctrine_Relation_Parser */ public function bind($name, $options = array()) { - if (isset($this->relations[$name])) { - unset($this->relations[$name]); + if (isset($this->_relations[$name])) { + unset($this->_relations[$name]); } $e = explode(' as ', $name); @@ -111,7 +111,7 @@ class Doctrine_Relation_Parser if ( ! isset($options['type'])) { throw new Doctrine_Relation_Exception('Relation type not set.'); } - + $this->_pending[$alias] = array_merge($options, array('class' => $name, 'alias' => $alias)); return $this->_pending[$alias]; @@ -125,9 +125,6 @@ class Doctrine_Relation_Parser public function getRelation($alias, $recursive = true) { if (isset($this->_relations[$alias])) { - /*if ($alias == 'Groupuser') { - //var_dump($this->_relations[$alias]['foreign']); - }*/ return $this->_relations[$alias]; } @@ -139,16 +136,24 @@ class Doctrine_Relation_Parser $this->getRelations(); return $this->getRelation($alias, false); } else { - /*try { - throw new Doctrine_Table_Exception('Unknown relation alias ' . $alias); + try { + throw new Exception(); } catch (Exception $e) { - echo $e->getTraceAsString(); - echo "

"; - }*/ - throw new Doctrine_Table_Exception('Unknown relation alias ' . $alias); + //echo "" . "
"; + ///echo $e->getTraceAsString() . "


"; + } + throw new Doctrine_Relation_Exception("Unknown relation '$alias'."); } } + public function addRelation($name, Doctrine_Relation $relation) + { + if (isset($this->_relations[$name])) { + throw new Doctrine_Relation_Exception("Relation '$name' does already exist."); + } + $this->_relations[$name] = $relation; + } + /** * Loads a relation and puts it into the collection of loaded relations. * In the process of initializing a relation it is common that multiple other, closely related @@ -164,11 +169,11 @@ class Doctrine_Relation_Parser // if it does we are dealing with an association relation (many-many) if (isset($def['refClass'])) { $def = $this->completeAssocDefinition($def); - $localClasses = array_merge($this->_table->getOption('parents'), array($this->_table->getComponentName())); + $localClasses = array_merge($this->_table->getOption('parents'), array($this->_table->getClassName())); // if the two many-many related components share the same table, we need // custom relation names to distinguish the relations. - if ($this->_table->getInheritanceType() == Doctrine::INHERITANCETYPE_SINGLE_TABLE && + /*if ($this->_table->getInheritanceType() == Doctrine::INHERITANCETYPE_SINGLE_TABLE && in_array($def['class'], $this->_table->getOption('subclasses'))) { if ( ! isset($def['refRelationName']) || ! isset($def['refReverseRelationName'])) { throw new Doctrine_Relation_Exception("Incomplete relation. Many-to-many relations between " @@ -176,9 +181,9 @@ class Doctrine_Relation_Parser . "a 'refRelationName' and a 'refReverseRelationName' to distinguish relations."); } $relationName = $def['refRelationName']; - } else { + } else {*/ $relationName = $def['refClass']; - } + //} if ( ! isset($this->_pending[$relationName]) && ! isset($this->_relations[$relationName])) { $this->_completeManyToManyRelation($def); @@ -220,14 +225,14 @@ class Doctrine_Relation_Parser // if the two many-many related components shared the same table, we need a relation name // to distinguish the relations. $relationName = $def['refClass']; - if (isset($def['refRelationName'])) { + /*if (isset($def['refRelationName'])) { $relationName .= ' as ' . $def['refRelationName']; - } + }*/ // add a relation pointing from the intermediary table to the table of this parser $parser = $def['refTable']->getRelationParser(); - if ( ! $parser->hasRelation($this->_table->getComponentName())) { - $parser->bind($this->_table->getComponentName(), + if ( ! $parser->hasRelation($this->_table->getClassName())) { + $parser->bind($this->_table->getClassName(), array('type' => Doctrine_Relation::ONE, 'local' => $def['local'], 'foreign' => $idColumnName, @@ -280,7 +285,7 @@ class Doctrine_Relation_Parser $def[$key] = $impl; } - return $conn->getTable($def[$key]); + return $conn->getMetadata($def[$key]); } protected function _isTemplate($className) @@ -345,7 +350,7 @@ class Doctrine_Relation_Parser * * @param Doctrine_Table $table table object to retrieve identifiers from */ - public function getIdentifiers(Doctrine_Table $table) + public function getIdentifiers($table) { $componentNameToLower = strtolower($table->getComponentName()); if (is_array($table->getIdentifier())) { @@ -368,13 +373,13 @@ class Doctrine_Relation_Parser * @param Doctrine_Table $foreignTable foreign table object * @return array an array of column names */ - public function guessColumns(array $classes, Doctrine_Table $foreignTable) + public function guessColumns(array $classes, $foreignTable) { $conn = $this->_table->getConnection(); foreach ($classes as $class) { try { - $table = $conn->getTable($class); + $table = $conn->getClassMetadata($class); } catch (Doctrine_Table_Exception $e) { continue; } @@ -415,9 +420,18 @@ class Doctrine_Relation_Parser $def['localTable'] = $this->_table; $foreignClasses = array_merge($def['table']->getOption('parents'), array($def['class'])); - $localClasses = array_merge($this->_table->getOption('parents'), array($this->_table->getComponentName())); + $localClasses = array_merge($this->_table->getOption('parents'), array($this->_table->getClassName())); $localIdentifierColumnNames = $this->_table->getIdentifierColumnNames(); + if ((count($localIdentifierColumnNames) - 1) < 0) { + echo $this->_table->getClassName(); + var_dump($this->_table->getIdentifier()); + try { + throw new Exception(); + } catch (Exception $e) { + echo $e->getTraceAsString() . "
"; + } + } $localIdColumnName = $localIdentifierColumnNames[count($localIdentifierColumnNames) - 1]; $foreignIdentifierColumnNames = $def['table']->getIdentifierColumnNames(); $foreignIdColumnName = $foreignIdentifierColumnNames[count($foreignIdentifierColumnNames) - 1]; @@ -462,14 +476,14 @@ class Doctrine_Relation_Parser // the following loops are needed for covering inheritance foreach ($localClasses as $class) { - $table = $conn->getTable($class); + $table = $conn->getClassMetadata($class); $identifierColumnNames = $table->getIdentifierColumnNames(); $idColumnName = array_pop($identifierColumnNames); $column = strtolower($table->getComponentName()) . '_' . $idColumnName; foreach ($foreignClasses as $class2) { - $table2 = $conn->getTable($class2); + $table2 = $conn->getClassMetadata($class2); if ($table2->hasColumn($column)) { $def['foreign'] = $column; $def['local'] = $idColumnName; @@ -479,14 +493,14 @@ class Doctrine_Relation_Parser } foreach ($foreignClasses as $class) { - $table = $conn->getTable($class); + $table = $conn->getClassMetadata($class); $identifierColumnNames = $table->getIdentifierColumnNames(); $idColumnName = array_pop($identifierColumnNames); $column = strtolower($table->getComponentName()) . '_' . $idColumnName; foreach ($localClasses as $class2) { - $table2 = $conn->getTable($class2); + $table2 = $conn->getClassMetadata($class2); if ($table2->hasColumn($column)) { $def['foreign'] = $idColumnName; $def['local'] = $column; diff --git a/lib/Doctrine/Table/Factory.php b/lib/Doctrine/Table/Factory.php index 6dfdbcfd6..a7ac27d56 100644 --- a/lib/Doctrine/Table/Factory.php +++ b/lib/Doctrine/Table/Factory.php @@ -27,7 +27,7 @@ class Doctrine_Table_Factory * @param array $tables The metadata collection to which the loaded metadata is added. */ public function loadTables($name, array &$tables) - { + { $parentClass = $name; $parentClasses = array(); $parentClassWithTable = false; @@ -104,13 +104,6 @@ class Doctrine_Table_Factory } } - - protected function _createTable($domainClassName) - { - return $this->_loadMetaDataFromCode($table, $domainClassName); - - } - /** * Initializes the in-memory metadata for the domain class this mapper belongs to. * Uses reflection and code setup. @@ -187,11 +180,12 @@ class Doctrine_Table_Factory $joinedParents[] = $parentColumns[$columnName]['owner'];*/ $joinedParents[] = $parentTable->getComponentName(); } - } else { + }/* else { + //echo "adding primary key $columnName on ".$table->getComponentName().".
"; unset($definition['autoincrement']); $fullName = $columnName . ' as ' . $parentTable->getFieldName($columnName); $table->setColumn($fullName, $definition['type'], $definition['length'], $definition, true); - } + }*/ } } $table->setOption('joinedParents', array_values(array_unique($joinedParents))); @@ -289,7 +283,7 @@ class Doctrine_Table_Factory unset($definition['sequence']); // add the inherited primary key column - $fullName = $id . ' as ' . $rootTable->getFieldName($id); + $fullName = $rootTable->getColumnName($id) . ' as ' . $id; $table->setColumn($fullName, $definition['type'], $definition['length'], $definition, true); } diff --git a/lib/Doctrine/Template.php b/lib/Doctrine/Template.php index 23303f38e..dec1fd4e4 100644 --- a/lib/Doctrine/Template.php +++ b/lib/Doctrine/Template.php @@ -45,7 +45,7 @@ class Doctrine_Template extends Doctrine_Record_Abstract * * @param Doctrine_Table $_table the table object this Template belongs to */ - public function setTable(Doctrine_Table $table) + public function setTable($table) { $this->_table = $table; } diff --git a/lib/Doctrine/Tree.php b/lib/Doctrine/Tree.php index f39e015a1..2b425e8b4 100644 --- a/lib/Doctrine/Tree.php +++ b/lib/Doctrine/Tree.php @@ -49,7 +49,7 @@ class Doctrine_Tree * @param object $table instance of Doctrine_Table * @param array $options options */ - public function __construct(Doctrine_Table $table, $options) + public function __construct($table, $options) { $this->table = $table; $this->options = $options; @@ -92,7 +92,7 @@ class Doctrine_Tree * @return object $options instance of Doctrine_Node * @throws Doctrine_Exception if class does not extend Doctrine_Tree */ - public static function factory(Doctrine_Table $table, $implName, $options = array()) + public static function factory($table, $implName, $options = array()) { $class = 'Doctrine_Tree_' . $implName; if ( ! class_exists($class)) { diff --git a/lib/Doctrine/Tree/NestedSet.php b/lib/Doctrine/Tree/NestedSet.php index 25b78eef3..c6e21eb3e 100644 --- a/lib/Doctrine/Tree/NestedSet.php +++ b/lib/Doctrine/Tree/NestedSet.php @@ -41,7 +41,7 @@ class Doctrine_Tree_NestedSet extends Doctrine_Tree implements Doctrine_Tree_Int * @param object $table instance of Doctrine_Table * @param array $options options */ - public function __construct(Doctrine_Table $table, $options) + public function __construct($table, $options) { // set default many root attributes $options['hasManyRoots'] = isset($options['hasManyRoots']) ? $options['hasManyRoots'] : false; diff --git a/lib/Doctrine/Validator.php b/lib/Doctrine/Validator.php index 33a3f2692..865ff8de3 100644 --- a/lib/Doctrine/Validator.php +++ b/lib/Doctrine/Validator.php @@ -21,7 +21,7 @@ /** * Doctrine_Validator - * Doctrine_Validator performs validations in record properties + * Doctrine_Validator performs validations on record properties * * @package Doctrine * @subpackage Validator @@ -105,14 +105,15 @@ class Doctrine_Validator extends Doctrine_Locator_Injectable foreach ($column as $name => $args) { if (empty($name) - || $name == 'primary' - || $name == 'protected' - || $name == 'autoincrement' - || $name == 'default' - || $name == 'values' - || $name == 'sequence' - || $name == 'zerofill' - || $name == 'scale') { + || $name == 'primary' + || $name == 'protected' + || $name == 'autoincrement' + || $name == 'default' + || $name == 'values' + || $name == 'sequence' + || $name == 'zerofill' + || $name == 'scale' + || $name == 'inherited') { continue; } diff --git a/models/Account.php b/models/Account.php index 6863cae85..adf2f7628 100644 --- a/models/Account.php +++ b/models/Account.php @@ -1,10 +1,10 @@ hasColumn('entity_id', 'integer'); - $this->hasColumn('amount', 'integer'); + $class->setColumn('entity_id', 'integer'); + $class->setColumn('amount', 'integer'); } } diff --git a/models/Address.php b/models/Address.php index 9d423c30f..20f559d14 100644 --- a/models/Address.php +++ b/models/Address.php @@ -1,13 +1,11 @@ hasMany('User', array('local' => 'address_id', + $class->setColumn('address', 'string', 200); + $class->hasMany('User', array('local' => 'address_id', 'foreign' => 'user_id', 'refClass' => 'EntityAddress')); } - public function setTableDefinition() { - $this->hasColumn('address', 'string', 200); - } } diff --git a/models/Album.php b/models/Album.php index 65cad1b2d..12079aab4 100644 --- a/models/Album.php +++ b/models/Album.php @@ -1,17 +1,14 @@ hasMany('Song', array('local' => 'id', 'foreign' => 'album_id')); - $this->hasOne('User', array('local' => 'user_id', + $class->setColumn('user_id', 'integer'); + $class->setColumn('name', 'string',20); + $class->hasMany('Song', array('local' => 'id', 'foreign' => 'album_id')); + $class->hasOne('User', array('local' => 'user_id', 'foreign' => 'id', 'onDelete' => 'CASCADE')); } - public function setTableDefinition() - { - $this->hasColumn('user_id', 'integer'); - $this->hasColumn('name', 'string',20); - } } diff --git a/models/App.php b/models/App.php index 7e5952415..fc09a7566 100644 --- a/models/App.php +++ b/models/App.php @@ -1,13 +1,11 @@ hasColumn('name', 'string', 32); - $this->hasColumn('user_id', 'integer', 11); - $this->hasColumn('app_category_id', 'integer', 11); - } - public function setUp() { - $this->hasOne('User', 'User.id'); - $this->hasMany('App_Category as Category', 'App_Category.id'); - } + public static function initMetadata($class) { + $class->setColumn('name', 'string', 32); + $class->setColumn('user_id', 'integer', 11); + $class->setColumn('app_category_id', 'integer', 11); + $class->hasOne('User', array('local' => 'user_id', 'foreign' => 'id')); + $class->hasOne('App_Category as Category', array('local' => 'app_category_id', 'foreign' => 'id')); + } } diff --git a/models/App_Category.php b/models/App_Category.php index e61c25fa8..5d5caaeb5 100644 --- a/models/App_Category.php +++ b/models/App_Category.php @@ -1,11 +1,9 @@ hasColumn('name', 'string', 32); - $this->hasColumn('parent_id', 'integer'); - } - public function setUp() { - $this->hasMany('App', 'App.app_category_id'); - $this->hasMany('App_Category as Parent', 'App_Category.parent_id'); + public static function initMetadata($class) { + $class->setColumn('name', 'string', 32); + $class->setColumn('parent_id', 'integer'); + $class->hasMany('App', array('local' => 'id', 'foreign' => 'app_category_id')); + $class->hasOne('App_Category as Parent', array('local' => 'parent_id', 'foreign' => 'id')); } } diff --git a/models/App_User.php b/models/App_User.php index f570269bb..e70d731c3 100644 --- a/models/App_User.php +++ b/models/App_User.php @@ -1,15 +1,13 @@ hasColumn('first_name', 'string', 32); - $this->hasColumn('last_name', 'string', 32); - $this->hasColumn('email', 'string', 128, 'email'); - $this->hasColumn('username', 'string', 16, 'unique, nospace'); - $this->hasColumn('password', 'string', 128, 'notblank'); - $this->hasColumn('country', 'string', 2, 'country'); - $this->hasColumn('zipcode', 'string', 9, 'nospace'); + public static function initMetadata($class) { + $class->setColumn('first_name', 'string', 32); + $class->setColumn('last_name', 'string', 32); + $class->setColumn('email', 'string', 128, 'email'); + $class->setColumn('username', 'string', 16, 'unique, nospace'); + $class->setColumn('password', 'string', 128, 'notblank'); + $class->setColumn('country', 'string', 2, 'country'); + $class->setColumn('zipcode', 'string', 9, 'nospace'); + $class->hasMany('App', array('local' => 'id', 'foreign' => 'user_id')); } - public function setUp() { - $this->hasMany('App', 'App.user_id'); - } } diff --git a/models/Assignment.php b/models/Assignment.php index 3d2f8b722..0cc880cb4 100644 --- a/models/Assignment.php +++ b/models/Assignment.php @@ -1,8 +1,8 @@ hasColumn('task_id', 'integer'); - $this->hasColumn('resource_id', 'integer'); + public static function initMetadata($class) { + $class->setColumn('task_id', 'integer'); + $class->setColumn('resource_id', 'integer'); } } diff --git a/models/Auth.php b/models/Auth.php index 23df462ae..04730307c 100644 --- a/models/Auth.php +++ b/models/Auth.php @@ -1,14 +1,11 @@ hasColumn('roleid', 'integer', 10); - $this->hasColumn('name', 'string', 50); - } - public function setUp() - { - $this->hasOne('Role', array('local' => 'roleid', 'foreign' => 'id')); + $class->setColumn('roleid', 'integer', 10); + $class->setColumn('name', 'string', 50); + $class->hasOne('Role', array('local' => 'roleid', 'foreign' => 'id')); } } diff --git a/models/Author.php b/models/Author.php index 1b48b80a3..1b272f1fa 100644 --- a/models/Author.php +++ b/models/Author.php @@ -1,15 +1,12 @@ hasOne('Book', array('local' => 'book_id', + $class->setColumn('book_id', 'integer'); + $class->setColumn('name', 'string',20); + $class->hasOne('Book', array('local' => 'book_id', 'foreign' => 'id', 'onDelete' => 'CASCADE')); } - public function setTableDefinition() - { - $this->hasColumn('book_id', 'integer'); - $this->hasColumn('name', 'string',20); - } } diff --git a/models/BadlyNamed__Class.php b/models/BadlyNamed__Class.php index 75c793370..7e7150be2 100644 --- a/models/BadlyNamed__Class.php +++ b/models/BadlyNamed__Class.php @@ -1,8 +1,7 @@ setTableName('bar'); - $this->hasColumn('name', 'string', 200); - } - public function setUp() - { - $this->hasMany('FooRecord as Foo', array('local' => 'barId', 'foreign' => 'fooId', 'refClass' => 'FooBarRecord')); + $class->setTableName('bar'); + $class->setColumn('name', 'string', 200); + $class->hasMany('FooRecord as Foo', array('local' => 'barId', 'foreign' => 'fooId', 'refClass' => 'FooBarRecord')); } } diff --git a/models/BaseSymfonyRecord.php b/models/BaseSymfonyRecord.php index e8a45d68e..bb04a5f91 100644 --- a/models/BaseSymfonyRecord.php +++ b/models/BaseSymfonyRecord.php @@ -1,13 +1,9 @@ hasColumn('name', 'string', 30); + $class->setColumn('name', 'string', 30); } } diff --git a/models/Blog.php b/models/Blog.php index 5b539c9a1..ceb1bc501 100644 --- a/models/Blog.php +++ b/models/Blog.php @@ -1,32 +1,23 @@ loadTemplate('Taggable'); + $class->loadTemplate('Taggable'); } } class Taggable extends Doctrine_Template { - public function setUp() + public static function initMetadata($class) { //$this->hasMany('[Component]TagTemplate as Tag'); } } class TagTemplate extends Doctrine_Record { - public function setTableDefinition() + public static function initMetadata($class) { - $this->hasColumn('name', 'string', 100); - $this->hasColumn('description', 'string'); - } - - public function setUp() - { - //$this->hasOne('[Component]', array('onDelete' => 'CASCADE')); + $class->setColumn('name', 'string', 100); + $class->setColumn('description', 'string'); } } diff --git a/models/BlogTag.php b/models/BlogTag.php index f20552ab7..d8b64cb81 100644 --- a/models/BlogTag.php +++ b/models/BlogTag.php @@ -1,13 +1,10 @@ -hasColumn('name', 'string', 100); - $this->hasColumn('description', 'string'); + $class->setColumn('name', 'string', 100); + $class->setColumn('description', 'string'); + $class->hasOne('Blog', array('onDelete' => 'CASCADE')); } - public function setUp() - { - $this->hasOne('Blog', array('onDelete' => 'CASCADE')); - } -} +} diff --git a/models/BoardWithPosition.php b/models/BoardWithPosition.php index e7a201ab4..a9b664383 100644 --- a/models/BoardWithPosition.php +++ b/models/BoardWithPosition.php @@ -1,10 +1,8 @@ hasColumn('position', 'integer'); - $this->hasColumn('category_id', 'integer'); - } - public function setUp() { - $this->hasOne('CategoryWithPosition as Category', array('local' => 'category_id', 'foreign' => 'id', 'onDelete' => 'CASCADE')); + public static function initMetadata($class) { + $class->setColumn('position', 'integer'); + $class->setColumn('category_id', 'integer'); + $class->hasOne('CategoryWithPosition as Category', array('local' => 'category_id', 'foreign' => 'id', 'onDelete' => 'CASCADE')); } } diff --git a/models/Book.php b/models/Book.php index cb28ec4f8..3864f4fe5 100644 --- a/models/Book.php +++ b/models/Book.php @@ -1,16 +1,13 @@ hasMany('Author', array('local' => 'id', 'foreign' => 'book_id')); - $this->hasOne('User', array('local' => 'user_id', + $class->setColumn('user_id', 'integer'); + $class->setColumn('name', 'string',20); + $class->hasMany('Author', array('local' => 'id', 'foreign' => 'book_id')); + $class->hasOne('User', array('local' => 'user_id', 'foreign' => 'id', 'onDelete' => 'CASCADE')); } - public function setTableDefinition() - { - $this->hasColumn('user_id', 'integer'); - $this->hasColumn('name', 'string',20); - } } diff --git a/models/Bookmark.php b/models/Bookmark.php index a4e6437e4..da49309c1 100644 --- a/models/Bookmark.php +++ b/models/Bookmark.php @@ -1,9 +1,9 @@ hasColumn('user_id', 'integer', null, array('primary' => true)); - $this->hasColumn('page_id', 'integer', null, array('primary' => true)); + $class->setColumn('user_id', 'integer', null, array('primary' => true)); + $class->setColumn('page_id', 'integer', null, array('primary' => true)); } } diff --git a/models/BookmarkUser.php b/models/BookmarkUser.php index 7759a3e18..37e8bcfd7 100644 --- a/models/BookmarkUser.php +++ b/models/BookmarkUser.php @@ -1,14 +1,11 @@ hasMany('Bookmark as Bookmarks', + $class->setColumn('name', 'string', 30); + $class->hasMany('Bookmark as Bookmarks', array('local' => 'id', 'foreign' => 'user_id')); } - public function setTableDefinition() - { - $this->hasColumn('name', 'string', 30); - } } diff --git a/models/BooleanTest.php b/models/BooleanTest.php index 748a6fa2b..ad1df2dbe 100644 --- a/models/BooleanTest.php +++ b/models/BooleanTest.php @@ -1,7 +1,7 @@ hasColumn('is_working', 'boolean'); - $this->hasColumn('is_working_notnull', 'boolean', 1, array('default' => false, 'notnull' => true)); + public static function initMetadata($class) { + $class->setColumn('is_working', 'boolean'); + $class->setColumn('is_working_notnull', 'boolean', 1, array('default' => false, 'notnull' => true)); } } diff --git a/models/CPK_Association.php b/models/CPK_Association.php index df9de93d8..52309dab4 100644 --- a/models/CPK_Association.php +++ b/models/CPK_Association.php @@ -1,7 +1,7 @@ hasColumn('test1_id', 'integer', 11, 'primary'); - $this->hasColumn('test2_id', 'integer', 11, 'primary'); + public static function initMetadata($class) { + $class->setColumn('test1_id', 'integer', 11, 'primary'); + $class->setColumn('test2_id', 'integer', 11, 'primary'); } } diff --git a/models/CPK_Test.php b/models/CPK_Test.php index a850342bb..726a8c34b 100644 --- a/models/CPK_Test.php +++ b/models/CPK_Test.php @@ -1,9 +1,7 @@ hasColumn('name', 'string', 255); - } - public function setUp() { - $this->hasMany('CPK_Test2 as Test', 'CPK_Association.test2_id'); + public static function initMetadata($class) { + $class->setColumn('name', 'string', 255); + $class->hasMany('CPK_Test2 as Test', array('local' => 'test_id', 'foreign' => 'test2_id', 'refClass' => 'CPK_Association')); } } diff --git a/models/CPK_Test2.php b/models/CPK_Test2.php index 9744ac03f..62f68eb8d 100644 --- a/models/CPK_Test2.php +++ b/models/CPK_Test2.php @@ -1,9 +1,7 @@ hasColumn('name', 'string', 255); - } - public function setUp() { - $this->hasMany('CPK_Test as Test', 'CPK_Association.test1_id'); + public static function initMetadata($class) { + $class->setColumn('name', 'string', 255); + $class->hasMany('CPK_Test as Test', array('local' => 'test2_id', 'test1_id', 'refClass' => 'CPK_Association')); } } diff --git a/models/CascadeDeleteRelatedTest.php b/models/CascadeDeleteRelatedTest.php index 15c34f295..03d1bc8b8 100644 --- a/models/CascadeDeleteRelatedTest.php +++ b/models/CascadeDeleteRelatedTest.php @@ -1,19 +1,16 @@ hasColumn('name', 'string'); - $this->hasColumn('cscd_id', 'integer'); - } - public function setUp() - { - $this->hasOne('CascadeDeleteTest', array('local' => 'cscd_id', + $class->setColumn('name', 'string'); + $class->setColumn('cscd_id', 'integer'); + $class->hasOne('CascadeDeleteTest', array('local' => 'cscd_id', 'foreign' => 'id', 'onDelete' => 'CASCADE', 'onUpdate' => 'SET NULL')); - $this->hasMany('CascadeDeleteRelatedTest2 as Related', + $class->hasMany('CascadeDeleteRelatedTest2 as Related', array('local' => 'id', 'foreign' => 'cscd_id')); } diff --git a/models/CascadeDeleteRelatedTest2.php b/models/CascadeDeleteRelatedTest2.php index 46049e104..b840019d1 100644 --- a/models/CascadeDeleteRelatedTest2.php +++ b/models/CascadeDeleteRelatedTest2.php @@ -1,14 +1,11 @@ hasColumn('name', 'string'); - $this->hasColumn('cscd_id', 'integer'); - } - public function setUp() - { - $this->hasOne('CascadeDeleteRelatedTest', array('local' => 'cscd_id', + $class->setColumn('name', 'string'); + $class->setColumn('cscd_id', 'integer'); + $class->hasOne('CascadeDeleteRelatedTest', array('local' => 'cscd_id', 'foreign' => 'id', 'onDelete' => 'SET NULL')); } diff --git a/models/CascadeDeleteTest.php b/models/CascadeDeleteTest.php index 9cd6698d3..d60de0686 100644 --- a/models/CascadeDeleteTest.php +++ b/models/CascadeDeleteTest.php @@ -1,13 +1,10 @@ hasColumn('name', 'string'); - } - public function setUp() - { - $this->hasMany('CascadeDeleteRelatedTest as Related', + $class->setColumn('name', 'string'); + $class->hasMany('CascadeDeleteRelatedTest as Related', array('local' => 'id', 'foreign' => 'cscd_id')); } diff --git a/models/CategoryNestedSet.php b/models/CategoryNestedSet.php index 6fa329acc..96e61be75 100644 --- a/models/CategoryNestedSet.php +++ b/models/CategoryNestedSet.php @@ -1,17 +1,12 @@ setTableName('category_nested_set'); - $this->hasColumn('id', 'integer', 4, array('primary' => true, 'autoincrement' => true)); - $this->hasColumn('name', 'string', 255, array('notnull' => true)); + $class->setTableName('category_nested_set'); + $class->setColumn('id', 'integer', 4, array('primary' => true, 'autoincrement' => true)); + $class->setColumn('name', 'string', 255, array('notnull' => true)); - $this->actAs('NestedSet'); + $class->actAs('NestedSet'); } - - public function setUp() - { - - } -} \ No newline at end of file +} diff --git a/models/CategoryWithPosition.php b/models/CategoryWithPosition.php index d205e3922..7f78f3dc1 100644 --- a/models/CategoryWithPosition.php +++ b/models/CategoryWithPosition.php @@ -1,10 +1,8 @@ hasColumn('position', 'integer'); - $this->hasColumn('name', 'string', 255); + public static function initMetadata($class) { + $class->setColumn('position', 'integer'); + $class->setColumn('name', 'string', 255); + $class->hasMany('BoardWithPosition as Boards', array('local' => 'id' , 'foreign' => 'category_id')); } - public function setUp() { - $this->hasMany('BoardWithPosition as Boards', array('local' => 'id' , 'foreign' => 'category_id')); - } } diff --git a/models/CheckConstraintTest.php b/models/CheckConstraintTest.php index a1ed16357..caac2c8cf 100644 --- a/models/CheckConstraintTest.php +++ b/models/CheckConstraintTest.php @@ -1,10 +1,10 @@ hasColumn('price', 'decimal', 2, array('max' => 5000, 'min' => 100)); - $this->hasColumn('discounted_price', 'decimal', 2); - $this->check('price > discounted_price'); + $class->setColumn('price', 'decimal', 2, array('max' => 5000, 'min' => 100)); + $class->setColumn('discounted_price', 'decimal', 2); + $class->check('price > discounted_price'); } } diff --git a/models/ClientModel.php b/models/ClientModel.php index 894c80355..6c0d76553 100644 --- a/models/ClientModel.php +++ b/models/ClientModel.php @@ -1,62 +1,47 @@ setTableName('clients'); + $class->setTableName('clients'); - $this->hasColumn('id', 'integer', 4, array('notnull' => true, + $class->setColumn('id', 'integer', 4, array('notnull' => true, 'primary' => true, 'autoincrement' => true, 'unsigned' => true)); - $this->hasColumn('short_name', 'string', 32, array('notnull' => true, 'notblank', 'unique' => true)); - } - - public function setUp() - { - $this->hasMany('AddressModel', array('local' => 'client_id', 'foreign' => 'address_id', 'refClass' => 'ClientToAddressModel')); + $class->setColumn('short_name', 'string', 32, array('notnull' => true, 'notblank', 'unique' => true)); + $class->hasMany('AddressModel', array('local' => 'client_id', 'foreign' => 'address_id', 'refClass' => 'ClientToAddressModel')); } } class ClientToAddressModel extends Doctrine_Record { - public function setTableDefinition() + public static function initMetadata($class) { - $this->setTableName('clients_to_addresses'); + $class->setTableName('clients_to_addresses'); - $this->hasColumn('client_id', 'integer', 11, array('primary' => true)); - $this->hasColumn('address_id', 'integer', 11, array('primary' => true)); - } - - public function construct() - { - } - - public function setUp() - { - $this->hasOne('ClientModel', array('local' => 'client_id', 'foreign' => 'id', 'onDelete' => 'CASCADE')); - $this->hasOne('AddressModel', array('local' => 'address_id', 'foreign' => 'id', 'onDelete' => 'CASCADE')); + $class->setColumn('client_id', 'integer', 11, array('primary' => true)); + $class->setColumn('address_id', 'integer', 11, array('primary' => true)); + + $class->hasOne('ClientModel', array('local' => 'client_id', 'foreign' => 'id', 'onDelete' => 'CASCADE')); + $class->hasOne('AddressModel', array('local' => 'address_id', 'foreign' => 'id', 'onDelete' => 'CASCADE')); } } class AddressModel extends Doctrine_Record { - public function setTableDefinition() + public static function initMetadata($class) { - $this->setTableName('addresses'); + $class->setTableName('addresses'); - $this->hasColumn('id', 'integer', 11, array('autoincrement' => true, + $class->setColumn('id', 'integer', 11, array('autoincrement' => true, 'primary' => true )); - $this->hasColumn('address1', 'string', 255, array('notnull' => true, 'notblank')); - $this->hasColumn('address2', 'string', 255, array('notnull' => true)); - $this->hasColumn('city', 'string', 255, array('notnull' => true, 'notblank')); - $this->hasColumn('state', 'string', 10, array('notnull' => true, 'notblank', 'usstate')); - $this->hasColumn('zip', 'string', 15, array('notnull' => true, 'notblank', 'regexp' => '/^[0-9-]*$/')); - } - - public function setUp() - { - $this->hasMany('ClientModel', array('local' => 'address_id', 'foreign' => 'client_id', 'refClass' => 'ClientToAddressModel')); + $class->setColumn('address1', 'string', 255, array('notnull' => true, 'notblank')); + $class->setColumn('address2', 'string', 255, array('notnull' => true)); + $class->setColumn('city', 'string', 255, array('notnull' => true, 'notblank')); + $class->setColumn('state', 'string', 10, array('notnull' => true, 'notblank', 'usstate')); + $class->setColumn('zip', 'string', 15, array('notnull' => true, 'notblank', 'regexp' => '/^[0-9-]*$/')); + $class->hasMany('ClientModel', array('local' => 'address_id', 'foreign' => 'client_id', 'refClass' => 'ClientToAddressModel')); } } diff --git a/models/ColumnAliasTest.php b/models/ColumnAliasTest.php index 5f8e96713..d443e6f45 100644 --- a/models/ColumnAliasTest.php +++ b/models/ColumnAliasTest.php @@ -1,15 +1,12 @@ hasColumn('column1 as alias1', 'string', 200); - $this->hasColumn('column2 as alias2', 'integer', 4); - $this->hasColumn('another_column as anotherField', 'string', 50); - $this->hasColumn('book_id as bookId', 'integer', 4); - } - public function setUp() - { - $this->hasOne('Book as book', array('local' => 'book_id', 'foreign' => 'id')); + $class->setColumn('column1 as alias1', 'string', 200); + $class->setColumn('column2 as alias2', 'integer', 4); + $class->setColumn('another_column as anotherField', 'string', 50); + $class->setColumn('book_id as bookId', 'integer', 4); + $class->hasOne('Book as book', array('local' => 'book_id', 'foreign' => 'id')); } } diff --git a/models/ConcreteEmail.php b/models/ConcreteEmail.php index 99532aab0..82f9bc1d3 100644 --- a/models/ConcreteEmail.php +++ b/models/ConcreteEmail.php @@ -1,8 +1,8 @@ loadTemplate('EmailTemplate'); + $class->loadTemplate('EmailTemplate'); } } diff --git a/models/ConcreteGroup.php b/models/ConcreteGroup.php index 447c06f7e..abed50bb1 100644 --- a/models/ConcreteGroup.php +++ b/models/ConcreteGroup.php @@ -1,8 +1,8 @@ loadTemplate('GroupTemplate'); + $class->loadTemplate('GroupTemplate'); } } diff --git a/models/ConcreteGroupUser.php b/models/ConcreteGroupUser.php index 79cc1203b..a6d023c32 100644 --- a/models/ConcreteGroupUser.php +++ b/models/ConcreteGroupUser.php @@ -1,8 +1,8 @@ loadTemplate('GroupUserTemplate'); + $class->loadTemplate('GroupUserTemplate'); } } diff --git a/models/ConcreteInheritanceTestParent.php b/models/ConcreteInheritanceTestParent.php index 24a454ac0..9142d71ef 100644 --- a/models/ConcreteInheritanceTestParent.php +++ b/models/ConcreteInheritanceTestParent.php @@ -1,18 +1,16 @@ hasColumn('name', 'string'); + $class->setColumn('name', 'string'); } } class ConcreteInheritanceTestChild extends ConcreteInheritanceTestParent { - public function setTableDefinition() + public static function initMetadata($class) { - $this->hasColumn('age', 'integer'); - - parent::setTableDefinition(); + $class->setColumn('age', 'integer'); } } diff --git a/models/ConcreteUser.php b/models/ConcreteUser.php index 12a659d04..b41db0094 100644 --- a/models/ConcreteUser.php +++ b/models/ConcreteUser.php @@ -1,9 +1,9 @@ loadTemplate('UserTemplate'); + $class->loadTemplate('UserTemplate'); } } diff --git a/models/CoverageCodeN.php b/models/CoverageCodeN.php index fd62d172f..a16afbedd 100644 --- a/models/CoverageCodeN.php +++ b/models/CoverageCodeN.php @@ -1,14 +1,10 @@ setTableName('coverage_codes'); - $this->hasColumn('id', 'integer', 4, array('notnull' => true, 'primary' => true, 'autoincrement' => true)); - $this->hasColumn('code', 'integer', 4, array ( 'notnull' => true, 'notblank' => true,)); - $this->hasColumn('description', 'string', 4000, array ( 'notnull' => true, 'notblank' => true,)); + public static function initMetadata($class) { + $class->setTableName('coverage_codes'); + $class->setColumn('id', 'integer', 4, array('notnull' => true, 'primary' => true, 'autoincrement' => true)); + $class->setColumn('code', 'integer', 4, array ( 'notnull' => true, 'notblank' => true,)); + $class->setColumn('description', 'string', 4000, array ( 'notnull' => true, 'notblank' => true,)); } - - public function setUp(){ -# $this->index('code', array('fields' => 'code')); - } } diff --git a/models/CustomPK.php b/models/CustomPK.php index e136136de..fc91d3a88 100644 --- a/models/CustomPK.php +++ b/models/CustomPK.php @@ -1,7 +1,7 @@ hasColumn('uid', 'integer',11, 'autoincrement|primary'); - $this->hasColumn('name', 'string',255); + public static function initMetadata($class) { + $class->setColumn('uid', 'integer',11, 'autoincrement|primary'); + $class->setColumn('name', 'string',255); } } diff --git a/models/CustomSequenceRecord.php b/models/CustomSequenceRecord.php index 4dd147fff..2ed58cf18 100644 --- a/models/CustomSequenceRecord.php +++ b/models/CustomSequenceRecord.php @@ -1,9 +1,9 @@ hasColumn('id', 'integer', null, array('primary', 'sequence' => 'custom_seq')); - $this->hasColumn('name', 'string'); + $class->setColumn('id', 'integer', null, array('primary', 'sequence' => 'custom_seq')); + $class->setColumn('name', 'string'); } } diff --git a/models/Data_File.php b/models/Data_File.php index b65abb109..8ca1c1af5 100644 --- a/models/Data_File.php +++ b/models/Data_File.php @@ -1,10 +1,8 @@ hasColumn('filename', 'string'); - $this->hasColumn('file_owner_id', 'integer'); - } - public function setUp() { - $this->hasOne('File_Owner', 'Data_File.file_owner_id'); + public static function initMetadata($class) { + $class->setColumn('filename', 'string'); + $class->setColumn('file_owner_id', 'integer'); + $class->hasOne('File_Owner', array('local' => 'file_owner_id', 'foreign' => 'id')); } } diff --git a/models/DateTest.php b/models/DateTest.php index 424664198..e04259a00 100644 --- a/models/DateTest.php +++ b/models/DateTest.php @@ -1,7 +1,7 @@ hasColumn('date', 'date', 20); + public static function initMetadata($class) { + $class->setColumn('date', 'date', 20); } } diff --git a/models/Description.php b/models/Description.php index fd9bada28..ad919165d 100644 --- a/models/Description.php +++ b/models/Description.php @@ -1,8 +1,8 @@ hasColumn('description', 'string',3000); - $this->hasColumn('file_md5', 'string',32); + public static function initMetadata($class) { + $class->setColumn('description', 'string',3000); + $class->setColumn('file_md5', 'string',32); } } diff --git a/models/Element.php b/models/Element.php index e4317e179..727e4becb 100644 --- a/models/Element.php +++ b/models/Element.php @@ -1,12 +1,10 @@ hasColumn('name', 'string', 100); - $this->hasColumn('parent_id', 'integer'); - } - public function setUp() { - $this->hasMany('Element as Child', 'Child.parent_id'); - $this->hasOne('Element as Parent', 'Element.parent_id'); + public static function initMetadata($class) { + $class->setColumn('name', 'string', 100); + $class->setColumn('parent_id', 'integer'); + $class->hasMany('Element as Child', array('local' => 'id', 'foreign' => 'parent_id')); + $class->hasOne('Element as Parent', array('local' => 'parent_id', 'foreign' => 'id')); } } diff --git a/models/Email.php b/models/Email.php index fa3cac123..92a6f5db9 100644 --- a/models/Email.php +++ b/models/Email.php @@ -1,9 +1,9 @@ hasColumn('address', 'string', 150, 'email|unique'); + $class->setColumn('address', 'string', 150, 'email|unique'); } diff --git a/models/Entity.php b/models/Entity.php index b8947a6b1..7b62ee854 100644 --- a/models/Entity.php +++ b/models/Entity.php @@ -1,26 +1,29 @@ hasOne('Email', array('local' => 'email_id')); - $this->hasMany('Phonenumber', array('local' => 'id', 'foreign' => 'entity_id')); - $this->hasOne('Account', array('foreign' => 'entity_id')); - $this->hasMany('Entity', array('local' => 'entity1', + $class->setColumn('id', 'integer',20, array('autoincrement' => true, 'primary' => true)); + $class->setColumn('name', 'string',50); + $class->setColumn('loginname', 'string',20, array('unique' => true)); + $class->setColumn('password', 'string',16); + $class->setColumn('type', 'integer'); + $class->setColumn('created', 'integer',11); + $class->setColumn('updated', 'integer',11); + $class->setColumn('email_id', 'integer'); + + $class->setSubclasses(array('Group', 'User')); + $class->setInheritanceType(Doctrine::INHERITANCETYPE_SINGLE_TABLE, array( + 'discriminatorColumn' => 'type', + 'discriminatorMap' => array(0 => 'User', 1 => 'Group', 2 => 'Entity') + )); + + $class->hasOne('Email', array('local' => 'email_id')); + $class->hasMany('Phonenumber', array('local' => 'id', 'foreign' => 'entity_id')); + $class->hasOne('Account', array('foreign' => 'entity_id')); + $class->hasMany('Entity', array('local' => 'entity1', 'refClass' => 'EntityReference', 'foreign' => 'entity2', 'equal' => true)); } - public function setTableDefinition() - { - $this->hasColumn('id', 'integer',20, 'autoincrement|primary'); - $this->hasColumn('name', 'string',50); - $this->hasColumn('loginname', 'string',20, array('unique')); - $this->hasColumn('password', 'string',16); - $this->hasColumn('type', 'integer',1); - $this->hasColumn('created', 'integer',11); - $this->hasColumn('updated', 'integer',11); - $this->hasColumn('email_id', 'integer'); - $this->setSubclasses(array("User" => array("type" => 0), "Group" => array("type" => 1))); - } } diff --git a/models/EntityAddress.php b/models/EntityAddress.php index c9e7af5a4..40cf91c51 100644 --- a/models/EntityAddress.php +++ b/models/EntityAddress.php @@ -1,9 +1,9 @@ hasColumn('user_id', 'integer', null, array('primary' => true)); - $this->hasColumn('address_id', 'integer', null, array('primary' => true)); + $class->setColumn('user_id', 'integer', null, array('primary' => true)); + $class->setColumn('address_id', 'integer', null, array('primary' => true)); } } diff --git a/models/EntityReference.php b/models/EntityReference.php index 093dd0554..4bfcca2dd 100644 --- a/models/EntityReference.php +++ b/models/EntityReference.php @@ -1,11 +1,10 @@ hasColumn('entity1', 'integer', null, 'primary'); - $this->hasColumn('entity2', 'integer', null, 'primary'); - //$this->setPrimaryKey(array('entity1', 'entity2')); + $class->setColumn('entity1', 'integer', null, 'primary'); + $class->setColumn('entity2', 'integer', null, 'primary'); } } diff --git a/models/EnumTest.php b/models/EnumTest.php index 12b12abed..b52cc7ac2 100644 --- a/models/EnumTest.php +++ b/models/EnumTest.php @@ -1,12 +1,10 @@ hasColumn('status', 'enum', 11, array('values' => array('open', 'verified', 'closed'))); - $this->hasColumn('text', 'string'); - } - public function setUp() { - $this->hasMany('EnumTest2 as Enum2', array('local' => 'id', 'foreign' => 'enum_test_id')); - $this->hasMany('EnumTest3 as Enum3', array('local' => 'text', 'foreign' => 'text')); + public static function initMetadata($class) { + $class->setColumn('status', 'enum', 11, array('values' => array('open', 'verified', 'closed'))); + $class->setColumn('text', 'string'); + $class->hasMany('EnumTest2 as Enum2', array('local' => 'id', 'foreign' => 'enum_test_id')); + $class->hasMany('EnumTest3 as Enum3', array('local' => 'text', 'foreign' => 'text')); } } diff --git a/models/EnumTest2.php b/models/EnumTest2.php index 5c7325921..fe9d71901 100644 --- a/models/EnumTest2.php +++ b/models/EnumTest2.php @@ -1,8 +1,8 @@ hasColumn('status', 'enum', 11, array('values' => array('open', 'verified', 'closed'))); - $this->hasColumn('enum_test_id', 'integer'); + public static function initMetadata($class) { + $class->setColumn('status', 'enum', 11, array('values' => array('open', 'verified', 'closed'))); + $class->setColumn('enum_test_id', 'integer'); } } diff --git a/models/EnumTest3.php b/models/EnumTest3.php index 0dc93a76e..53ae609f9 100644 --- a/models/EnumTest3.php +++ b/models/EnumTest3.php @@ -1,7 +1,7 @@ hasColumn('text', 'string', 10, array('primary' => true)); + public static function initMetadata($class) { + $class->setColumn('text', 'string', 10, array('primary' => true)); } } diff --git a/models/Error.php b/models/Error.php index 36c029e69..556d91d78 100644 --- a/models/Error.php +++ b/models/Error.php @@ -1,12 +1,10 @@ hasMany('Description', 'Description.file_md5', 'file_md5'); - } - public function setTableDefinition() { - $this->hasColumn('message', 'string',200); - $this->hasColumn('code', 'integer',11); - $this->hasColumn('file_md5', 'string',32, 'primary'); + public static function initMetadata($class) { + $class->setColumn('message', 'string',200); + $class->setColumn('code', 'integer',11); + $class->setColumn('file_md5', 'string',32, 'primary'); + $class->hasMany('Description', array('local' => 'file_md5', 'foreign' => 'file_md5')); } } diff --git a/models/EventListenerChainTest.php b/models/EventListenerChainTest.php index 8a235deba..792e961dd 100644 --- a/models/EventListenerChainTest.php +++ b/models/EventListenerChainTest.php @@ -1,10 +1,8 @@ hasColumn('name', 'string', 100); - } - public function setUp() { + public static function initMetadata($class) { + $class->setColumn('name', 'string', 100); $chain = new Doctrine_EventListener_Chain(); $chain->add(new Doctrine_EventListener_TestA()); $chain->add(new Doctrine_EventListener_TestB()); diff --git a/models/EventListenerTest.php b/models/EventListenerTest.php index 0a4f25c1d..bbaa6be53 100644 --- a/models/EventListenerTest.php +++ b/models/EventListenerTest.php @@ -1,11 +1,8 @@ hasColumn("name", "string", 100); - $this->hasColumn("password", "string", 8); - } - public function setUp() { - //$this->attribute(Doctrine::ATTR_LISTENER, new Doctrine_EventListener_AccessorInvoker()); + public static function initMetadata($class) { + $class->setColumn("name", "string", 100); + $class->setColumn("password", "string", 8); } public function getName($name) { return strtoupper($name); diff --git a/models/FieldNameTest.php b/models/FieldNameTest.php index e8612b707..736e0c240 100644 --- a/models/FieldNameTest.php +++ b/models/FieldNameTest.php @@ -1,12 +1,12 @@ hasColumn('someColumn', 'string', 200, array('default' => 'some string')); - $this->hasColumn('someEnum', 'enum', 4, array('default' => 'php', 'values' => array('php', 'java', 'python'))); - $this->hasColumn('someArray', 'array', 100, array('default' => array())); - $this->hasColumn('someObject', 'object', 200, array('default' => new stdClass)); - $this->hasColumn('someInt', 'integer', 20, array('default' => 11)); + $class->setColumn('someColumn', 'string', 200, array('default' => 'some string')); + $class->setColumn('someEnum', 'enum', 4, array('default' => 'php', 'values' => array('php', 'java', 'python'))); + $class->setColumn('someArray', 'array', 100, array('default' => array())); + $class->setColumn('someObject', 'object', 200, array('default' => new stdClass)); + $class->setColumn('someInt', 'integer', 20, array('default' => 11)); } } diff --git a/models/File_Owner.php b/models/File_Owner.php index 7f2379c98..444ac9bee 100644 --- a/models/File_Owner.php +++ b/models/File_Owner.php @@ -1,9 +1,7 @@ hasColumn('name', 'string', 255); - } - public function setUp() { - $this->hasOne('Data_File', 'Data_File.file_owner_id'); + public static function initMetadata($class) { + $class->setColumn('name', 'string', 255); + $class->hasOne('Data_File', array('local' => 'id', 'foreign' => 'file_owner_id')); } } diff --git a/models/FilterTest.php b/models/FilterTest.php index 707d889e2..cdedf3204 100644 --- a/models/FilterTest.php +++ b/models/FilterTest.php @@ -1,9 +1,7 @@ hasColumn('name', 'string',100); - } - public function setUp() { - $this->hasMany('FilterTest2 as filtered', 'FilterTest2.test1_id'); + public static function initMetadata($class) { + $class->setColumn('name', 'string',100); + $class->hasMany('FilterTest2 as filtered', array('local' => 'id', 'foreign' => 'test1_id')); } } diff --git a/models/FilterTest2.php b/models/FilterTest2.php index 4ceb5e52d..fb0080b9f 100644 --- a/models/FilterTest2.php +++ b/models/FilterTest2.php @@ -1,7 +1,7 @@ hasColumn('name', 'string',100); - $this->hasColumn('test1_id', 'integer'); + public static function initMetadata($class) { + $class->setColumn('name', 'string',100); + $class->setColumn('test1_id', 'integer'); } } diff --git a/models/FooBarRecord.php b/models/FooBarRecord.php index d32ec1cd5..423b2555f 100644 --- a/models/FooBarRecord.php +++ b/models/FooBarRecord.php @@ -1,9 +1,9 @@ hasColumn('fooId', 'integer', null, array('primary' => true)); - $this->hasColumn('barId', 'integer', null, array('primary' => true)); + $class->setColumn('fooId', 'integer', null, array('primary' => true)); + $class->setColumn('barId', 'integer', null, array('primary' => true)); } } diff --git a/models/FooForeignlyOwned.php b/models/FooForeignlyOwned.php index 6593d5d4a..18750a18b 100644 --- a/models/FooForeignlyOwned.php +++ b/models/FooForeignlyOwned.php @@ -1,9 +1,9 @@ hasColumn('name', 'string', 200); - $this->hasColumn('fooId', 'integer'); + $class->setColumn('name', 'string', 200); + $class->setColumn('fooId', 'integer'); } } diff --git a/models/FooForeignlyOwnedWithPK.php b/models/FooForeignlyOwnedWithPK.php index ef6df5b20..515f1465d 100644 --- a/models/FooForeignlyOwnedWithPK.php +++ b/models/FooForeignlyOwnedWithPK.php @@ -1,12 +1,8 @@ hasColumn('name', 'string', 200); - } - public function setUp() - { - //$this->hasOne('FooRecord', array('local' => 'id', 'foreign' => 'id')); + $class->setColumn('name', 'string', 200); } } diff --git a/models/FooLocallyOwned.php b/models/FooLocallyOwned.php index a30a229f4..6333c90b9 100644 --- a/models/FooLocallyOwned.php +++ b/models/FooLocallyOwned.php @@ -1,9 +1,9 @@ hasColumn('name', 'string', 200); + $class->setColumn('name', 'string', 200); } } diff --git a/models/FooRecord.php b/models/FooRecord.php index 569352441..caf112475 100644 --- a/models/FooRecord.php +++ b/models/FooRecord.php @@ -1,43 +1,38 @@ setTableName('foo'); + $class->setTableName('foo'); + $class->setColumn('name', 'string', 200, array('notnull' => true)); + $class->setColumn('parent_id', 'integer'); + $class->setColumn('local_foo', 'integer'); - $this->hasColumn('name', 'string', 200, array('notnull' => true)); - $this->hasColumn('parent_id', 'integer'); - $this->hasColumn('local_foo', 'integer'); - } - public function setUp() - { - $this->hasMany('FooRecord as FooFriend', array('local' => 'foo1', + $class->hasMany('FooRecord as FooFriend', array('local' => 'foo1', 'foreign' => 'foo2', 'equal' => true, 'refClass' => 'FooReferenceRecord', )); - $this->hasMany('FooRecord as FooParents', array('local' => 'foo1', + $class->hasMany('FooRecord as FooParents', array('local' => 'foo1', 'foreign' => 'foo2', 'refClass' => 'FooReferenceRecord', 'onDelete' => 'RESTRICT', )); - $this->hasMany('FooRecord as FooChildren', array('local' => 'foo2', + $class->hasMany('FooRecord as FooChildren', array('local' => 'foo2', 'foreign' => 'foo1', 'refClass' => 'FooReferenceRecord', )); - $this->hasMany('FooRecord as Children', array('local' => 'id', 'foreign' => 'parent_id')); + $class->hasMany('FooRecord as Children', array('local' => 'id', 'foreign' => 'parent_id')); - $this->hasOne('FooRecord as Parent', array('local' => 'parent_id', 'foreign' => 'id', 'onDelete' => 'CASCADE')); - //$this->hasOne('FooForeignlyOwnedWithPk', array('local' => 'id', 'foreign' => 'id', 'constraint' => true)); - $this->hasOne('FooLocallyOwned', array('local' => 'local_foo', 'onDelete' => 'RESTRICT')); + $class->hasOne('FooRecord as Parent', array('local' => 'parent_id', 'foreign' => 'id', 'onDelete' => 'CASCADE')); + $class->hasOne('FooLocallyOwned', array('local' => 'local_foo', 'onDelete' => 'RESTRICT')); - $this->hasMany('BarRecord as Bar', array('local' => 'fooId', + $class->hasMany('BarRecord as Bar', array('local' => 'fooId', 'foreign' => 'barId', 'refClass' => 'FooBarRecord', 'onUpdate' => 'RESTRICT')); - } } diff --git a/models/FooReferenceRecord.php b/models/FooReferenceRecord.php index fb378065f..e003b8167 100644 --- a/models/FooReferenceRecord.php +++ b/models/FooReferenceRecord.php @@ -1,11 +1,10 @@ setTableName('foo_reference'); - - $this->hasColumn('foo1', 'integer', null, array('primary' => true)); - $this->hasColumn('foo2', 'integer', null, array('primary' => true)); + $class->setTableName('foo_reference'); + $class->setColumn('foo1', 'integer', null, array('primary' => true)); + $class->setColumn('foo2', 'integer', null, array('primary' => true)); } } diff --git a/models/ForeignKeyTest.php b/models/ForeignKeyTest.php index 69f618ac1..27edb6bec 100644 --- a/models/ForeignKeyTest.php +++ b/models/ForeignKeyTest.php @@ -1,24 +1,22 @@ hasColumn('name', 'string', null); - $this->hasColumn('code', 'integer', 4); - $this->hasColumn('content', 'string', 4000); - $this->hasColumn('parent_id', 'integer'); + $class->setColumn('name', 'string', null); + $class->setColumn('code', 'integer', 4); + $class->setColumn('content', 'string', 4000); + $class->setColumn('parent_id', 'integer'); - $this->hasOne('ForeignKeyTest as Parent', + $class->hasOne('ForeignKeyTest as Parent', array('local' => 'parent_id', 'foreign' => 'id', 'onDelete' => 'CASCADE', 'onUpdate' => 'RESTRICT') ); - $this->hasMany('ForeignKeyTest as Children', - 'ForeignKeyTest.parent_id'); - - $this->option('type', 'INNODB'); + $class->hasMany('ForeignKeyTest as Children', array('local' => 'id', 'foreign' => 'parent_id')); + $class->setTableOption('type', 'INNODB'); } } diff --git a/models/ForeignKeyTest2.php b/models/ForeignKeyTest2.php index ef325e791..6f4457cc3 100644 --- a/models/ForeignKeyTest2.php +++ b/models/ForeignKeyTest2.php @@ -1,11 +1,10 @@ hasColumn('name', 'string', null); - $this->hasColumn('foreignkey', 'integer'); - - $this->hasOne('ForeignKeyTest', 'ForeignKeyTest2.foreignkey'); + $class->setColumn('name', 'string', null); + $class->setColumn('foreignkey', 'integer'); + $class->hasOne('ForeignKeyTest', array('local' => 'foreignkey', 'foreign' => 'id')); } } diff --git a/models/Forum_Board.php b/models/Forum_Board.php index 6bb679fc9..d11394949 100644 --- a/models/Forum_Board.php +++ b/models/Forum_Board.php @@ -1,13 +1,11 @@ hasColumn('category_id', 'integer', 10); - $this->hasColumn('name', 'string', 100); - $this->hasColumn('description', 'string', 5000); + public static function initMetadata($class) { + $class->setColumn('category_id', 'integer', 10); + $class->setColumn('name', 'string', 100); + $class->setColumn('description', 'string', 5000); + $class->hasOne('Forum_Category as Category', array('local' => 'category_id', 'foreign' => 'id')); + $class->hasMany('Forum_Thread as Threads', array('local' => 'id', 'foreign' => 'board_id')); } - public function setUp() { - $this->hasOne('Forum_Category as Category', array('local' => 'category_id', 'foreign' => 'id')); - $this->hasMany('Forum_Thread as Threads', array('local' => 'id', 'foreign' => 'board_id')); - } } diff --git a/models/Forum_Category.php b/models/Forum_Category.php index 5f635bb1f..00edd6293 100644 --- a/models/Forum_Category.php +++ b/models/Forum_Category.php @@ -1,14 +1,12 @@ hasColumn('root_category_id', 'integer', 10); - $this->hasColumn('parent_category_id', 'integer', 10); - $this->hasColumn('name', 'string', 50); - $this->hasColumn('description', 'string', 99999); - } - public function setUp() { - $this->hasMany('Forum_Category as Subcategory', 'Subcategory.parent_category_id'); - $this->hasOne('Forum_Category as Parent', 'Forum_Category.parent_category_id'); - $this->hasOne('Forum_Category as Rootcategory', 'Forum_Category.root_category_id'); + public static function initMetadata($class) { + $class->setColumn('root_category_id', 'integer', 10); + $class->setColumn('parent_category_id', 'integer', 10); + $class->setColumn('name', 'string', 50); + $class->setColumn('description', 'string', 99999); + $class->hasMany('Forum_Category as Subcategory', array('local' => 'id', 'foreign' => 'parent_category_id')); + $class->hasOne('Forum_Category as Parent', array('local' => 'parent_category_id', 'foreign' => 'id')); + $class->hasOne('Forum_Category as Rootcategory', array('local' => 'root_category_id', 'foreign' => 'id')); } } diff --git a/models/Forum_Entry.php b/models/Forum_Entry.php index 91817dec0..e88730468 100644 --- a/models/Forum_Entry.php +++ b/models/Forum_Entry.php @@ -1,16 +1,14 @@ hasColumn('author', 'string', 50); - $this->hasColumn('topic', 'string', 100); - $this->hasColumn('message', 'string', 99999); - $this->hasColumn('parent_entry_id', 'integer', 10); - $this->hasColumn('thread_id', 'integer', 10); - $this->hasColumn('date', 'integer', 10); - } - public function setUp() { - $this->hasOne('Forum_Entry as Parent', array('local' => 'id', 'foreign' => 'parent_entry_id')); - $this->hasOne('Forum_Thread as Thread', array('local' => 'thread_id', 'foreign' => 'id', 'onDelete' => 'CASCADE')); + public static function initMetadata($class) { + $class->setColumn('author', 'string', 50); + $class->setColumn('topic', 'string', 100); + $class->setColumn('message', 'string', 99999); + $class->setColumn('parent_entry_id', 'integer', 10); + $class->setColumn('thread_id', 'integer', 10); + $class->setColumn('date', 'integer', 10); + $class->hasOne('Forum_Entry as Parent', array('local' => 'id', 'foreign' => 'parent_entry_id')); + $class->hasOne('Forum_Thread as Thread', array('local' => 'thread_id', 'foreign' => 'id', 'onDelete' => 'CASCADE')); } } diff --git a/models/Forum_Thread.php b/models/Forum_Thread.php index afac222c7..19f8f1408 100644 --- a/models/Forum_Thread.php +++ b/models/Forum_Thread.php @@ -1,13 +1,11 @@ hasColumn('board_id', 'integer', 10); - $this->hasColumn('updated', 'integer', 10); - $this->hasColumn('closed', 'integer', 1); - } - public function setUp() { - $this->hasOne('Forum_Board as Board', array('local' => 'board_id', 'foreign' => 'id', 'onDelete' => 'CASCADE')); - $this->hasMany('Forum_Entry as Entries', array('local' => 'id', 'foreign' => 'thread_id')); + public static function initMetadata($class) { + $class->setColumn('board_id', 'integer', 10); + $class->setColumn('updated', 'integer', 10); + $class->setColumn('closed', 'integer', 1); + $class->hasOne('Forum_Board as Board', array('local' => 'board_id', 'foreign' => 'id', 'onDelete' => 'CASCADE')); + $class->hasMany('Forum_Entry as Entries', array('local' => 'id', 'foreign' => 'thread_id')); } } diff --git a/models/Group.php b/models/Group.php index 41d05a042..aeee66a27 100644 --- a/models/Group.php +++ b/models/Group.php @@ -8,19 +8,13 @@ class GroupTable { } class Group extends Entity { - public function setUp() + public static function initMetadata($class) { - parent::setUp(); - $this->hasMany('User', array( + $class->hasMany('User', array( 'local' => 'group_id', 'foreign' => 'user_id', - 'refClass' => 'Groupuser', - 'refRelationName' => 'GroupGroupuser', - 'refReverseRelationName' => 'UserGroupuser' + 'refClass' => 'Groupuser' )); - /*$this->hasMany('Groupuser as User', array( - 'local' => 'id', 'foreign' => 'group_id' - ));*/ } } diff --git a/models/GroupUser.php b/models/GroupUser.php deleted file mode 100644 index 7fedfe37d..000000000 --- a/models/GroupUser.php +++ /dev/null @@ -1,16 +0,0 @@ -hasColumn('added', 'integer'); - $this->hasColumn('group_id', 'integer', null /*,array('primary' => true)*/); - $this->hasColumn('user_id', 'integer', null /*,array('primary' => true)*/); - } - - public function setUp() - { - $this->hasOne('Group', array('local' => 'group_id', 'foreign' => 'id')); - $this->hasOne('User', array('local' => 'user_id', 'foreign' => 'id')); - } -} diff --git a/models/Groupuser.php b/models/Groupuser.php new file mode 100644 index 000000000..899693dd7 --- /dev/null +++ b/models/Groupuser.php @@ -0,0 +1,12 @@ +setColumn('added', 'integer'); + $class->setColumn('group_id', 'integer', null /*,array('primary' => true)*/); + $class->setColumn('user_id', 'integer', null /*,array('primary' => true)*/); + $class->hasOne('Group', array('local' => 'group_id', 'foreign' => 'id')); + $class->hasOne('User', array('local' => 'user_id', 'foreign' => 'id')); + } +} \ No newline at end of file diff --git a/models/GzipTest.php b/models/GzipTest.php index 64dc9996d..0856229e8 100644 --- a/models/GzipTest.php +++ b/models/GzipTest.php @@ -1,6 +1,6 @@ hasColumn('gzip', 'gzip', 100000); + public static function initMetadata($class) { + $class->setColumn('gzip', 'gzip', 100000); } } diff --git a/models/I18nTest.php b/models/I18nTest.php index c5aaae815..b6e6d0bbd 100644 --- a/models/I18nTest.php +++ b/models/I18nTest.php @@ -1,13 +1,10 @@ hasColumn('name', 'string', 200); - $this->hasColumn('title', 'string', 200); - } - public function setUp() - { - $this->actAs('I18n', array('fields' => array('name', 'title'))); + $class->setColumn('name', 'string', 200); + $class->setColumn('title', 'string', 200); + $class->actAs('I18n', array('fields' => array('name', 'title'))); } } diff --git a/models/InheritanceDeal.php b/models/InheritanceDeal.php index c1f40e3b6..2092c5cea 100644 --- a/models/InheritanceDeal.php +++ b/models/InheritanceDeal.php @@ -1,16 +1,12 @@ setTableName('inheritance_deal'); + $class->setTableName('inheritance_deal'); - $this->hasColumn('id', 'integer', 4, array ( 'primary' => true, 'autoincrement' => true,)); - $this->hasColumn('name', 'string', 255, array ()); - } - - public function setUp() - { - $this->hasMany('InheritanceUser as Users', array('refClass' => 'InheritanceDealUser', 'local' => 'entity_id', 'foreign' => 'user_id')); + $class->setColumn('id', 'integer', 4, array ( 'primary' => true, 'autoincrement' => true,)); + $class->setColumn('name', 'string', 255, array ()); + $class->hasMany('InheritanceUser as Users', array('refClass' => 'InheritanceDealUser', 'local' => 'entity_id', 'foreign' => 'user_id')); } } \ No newline at end of file diff --git a/models/InheritanceDealUser.php b/models/InheritanceDealUser.php index fbce252d5..c1943ad14 100644 --- a/models/InheritanceDealUser.php +++ b/models/InheritanceDealUser.php @@ -1,36 +1,27 @@ setInheritanceType(Doctrine::INHERITANCETYPE_SINGLE_TABLE, - array('InheritanceDealUser' => array('type' => 1))); - - $this->setTableName('inheritance_entity_user'); - - $this->hasColumn('type', 'integer', 4, array ( 'primary' => true,)); - $this->hasColumn('user_id', 'integer', 4, array ( 'primary' => true,)); - $this->hasColumn('entity_id', 'integer', 4, array ( 'primary' => true,)); - } - - public function setUp() - { + $class->setInheritanceType(Doctrine::INHERITANCETYPE_SINGLE_TABLE, array( + 'discriminatorColumn' => 'type', + 'discriminatorMap' => array(1 => 'InheritanceDealUser', 2 => 'InheritanceEntityUser') + )); + $class->setSubclasses(array('InheritanceDealUser')); + $class->setTableName('inheritance_entity_user'); + $class->setColumn('type', 'integer', 4, array ( 'primary' => true,)); + $class->setColumn('user_id', 'integer', 4, array ( 'primary' => true,)); + $class->setColumn('entity_id', 'integer', 4, array ( 'primary' => true,)); } } class InheritanceDealUser extends InheritanceEntityUser { - public function setTableDefinition() + public static function initMetadata($class) { - $this->hasColumn('user_id', 'integer', 4, array ( 'primary' => true,)); - $this->hasColumn('entity_id', 'integer', 4, array ( 'primary' => true,)); - } - - public function setUp() - { - parent::setUp(); - - $this->hasOne('InheritanceUser as User', array('local' => 'user_id', 'foreign' => 'id')); - $this->hasOne('InheritanceDeal as Deal', array('local' => 'entity_id', 'foreign' => 'id')); + $class->setColumn('user_id', 'integer', 4, array ( 'primary' => true,)); + $class->setColumn('entity_id', 'integer', 4, array ( 'primary' => true,)); + $class->hasOne('InheritanceUser as User', array('local' => 'user_id', 'foreign' => 'id')); + $class->hasOne('InheritanceDeal as Deal', array('local' => 'entity_id', 'foreign' => 'id')); } } \ No newline at end of file diff --git a/models/InheritanceUser.php b/models/InheritanceUser.php index fa9dacfe8..3c981d3ab 100644 --- a/models/InheritanceUser.php +++ b/models/InheritanceUser.php @@ -1,16 +1,12 @@ setTableName('inheritance_user'); + $class->setTableName('inheritance_user'); - $this->hasColumn('id', 'integer', 4, array ( 'primary' => true, 'autoincrement' => true,)); - $this->hasColumn('username', 'string', 128, array ( 'notnull' => true,)); - } - - public function setUp() - { - $this->hasMany('InheritanceDeal as Deals', array('refClass' => 'InheritanceDealUser', 'local' => 'user_id', 'foreign' => 'entity_id')); + $class->setColumn('id', 'integer', 4, array ( 'primary' => true, 'autoincrement' => true,)); + $class->setColumn('username', 'string', 128, array ( 'notnull' => true,)); + $class->hasMany('InheritanceDeal as Deals', array('refClass' => 'InheritanceDealUser', 'local' => 'user_id', 'foreign' => 'entity_id')); } } \ No newline at end of file diff --git a/models/JC1.php b/models/JC1.php index 6c5183426..68e9568df 100644 --- a/models/JC1.php +++ b/models/JC1.php @@ -1,8 +1,8 @@ hasColumn('c1_id', 'integer'); - $this->hasColumn('c2_id', 'integer'); + public static function initMetadata($class) { + $class->setColumn('c1_id', 'integer'); + $class->setColumn('c2_id', 'integer'); } } diff --git a/models/JC2.php b/models/JC2.php index 7f6c27cc4..8ee301049 100644 --- a/models/JC2.php +++ b/models/JC2.php @@ -1,8 +1,8 @@ hasColumn('c1_id', 'integer'); - $this->hasColumn('c2_id', 'integer'); + public static function initMetadata($class) { + $class->setColumn('c1_id', 'integer'); + $class->setColumn('c2_id', 'integer'); } } diff --git a/models/JC3.php b/models/JC3.php index a3d68cc5d..6c6dcbaed 100644 --- a/models/JC3.php +++ b/models/JC3.php @@ -1,8 +1,8 @@ hasColumn('c1_id', 'integer'); - $this->hasColumn('c2_id', 'integer'); + public static function initMetadata($class) { + $class->setColumn('c1_id', 'integer'); + $class->setColumn('c2_id', 'integer'); } } diff --git a/models/LiabilityCodeN.php b/models/LiabilityCodeN.php index 895c3f194..efda2e0bd 100644 --- a/models/LiabilityCodeN.php +++ b/models/LiabilityCodeN.php @@ -1,14 +1,10 @@ setTableName('liability_codes'); - $this->hasColumn('id', 'integer', 4, array('notnull' => true, 'primary' => true, 'autoincrement' => true)); - $this->hasColumn('code', 'integer', 4, array ( 'notnull' => true, 'notblank' => true,)); - $this->hasColumn('description', 'string', 4000, array ( 'notnull' => true, 'notblank' => true,)); + public static function initMetadata($class) { + $class->setTableName('liability_codes'); + $class->setColumn('id', 'integer', 4, array('notnull' => true, 'primary' => true, 'autoincrement' => true)); + $class->setColumn('code', 'integer', 4, array ( 'notnull' => true, 'notblank' => true,)); + $class->setColumn('description', 'string', 4000, array ( 'notnull' => true, 'notblank' => true,)); } - - public function setUp(){ -# $this->index('code', array('fields' => 'code')); - } } diff --git a/models/Location.php b/models/Location.php index 4cd8611d8..108b15223 100644 --- a/models/Location.php +++ b/models/Location.php @@ -1,14 +1,10 @@ hasColumn('lat', 'double', 10, array ()); - $this->hasColumn('lon', 'double', 10, array ()); - } - - public function setUp() - { - $this->hasMany('LocationI18n as LocationI18n', array('local' => 'id', 'foreign' => 'id')); + $class->setColumn('lat', 'double', 10, array ()); + $class->setColumn('lon', 'double', 10, array ()); + $class->hasMany('LocationI18n as LocationI18n', array('local' => 'id', 'foreign' => 'id')); } } diff --git a/models/LocationI18n.php b/models/LocationI18n.php index 5703b984f..3bdd64101 100644 --- a/models/LocationI18n.php +++ b/models/LocationI18n.php @@ -1,15 +1,11 @@ hasColumn('name', 'string', 50, array()); - $this->hasColumn('id', 'integer', 10, array('primary' => true)); - $this->hasColumn('culture', 'string', 2); - } - - public function setUp() - { - $this->hasOne('Location as Location', array('local' => 'id')); + $class->setColumn('name', 'string', 50, array()); + $class->setColumn('id', 'integer', 10, array('primary' => true)); + $class->setColumn('culture', 'string', 2); + $class->hasOne('Location as Location', array('local' => 'id')); } } diff --git a/models/Log_Entry.php b/models/Log_Entry.php index 8fe5778a8..0ad886e25 100644 --- a/models/Log_Entry.php +++ b/models/Log_Entry.php @@ -1,10 +1,8 @@ hasColumn('stamp', 'timestamp'); - $this->hasColumn('status_id', 'integer'); - } - public function setUp() { - $this->hasOne('Log_Status', 'Log_Entry.status_id'); + public static function initMetadata($class) { + $class->setColumn('stamp', 'timestamp'); + $class->setColumn('status_id', 'integer'); + $class->hasOne('Log_Status', array('local' => 'status_id', 'foreign' => 'id')); } } diff --git a/models/Log_Status.php b/models/Log_Status.php index e8540e858..6459f770c 100644 --- a/models/Log_Status.php +++ b/models/Log_Status.php @@ -1,6 +1,6 @@ hasColumn('name', 'string', 255); + public static function initMetadata($class) { + $class->setColumn('name', 'string', 255); } } diff --git a/models/M2MTest.php b/models/M2MTest.php index 39c72b28b..7994e5367 100644 --- a/models/M2MTest.php +++ b/models/M2MTest.php @@ -1,16 +1,12 @@ hasColumn('name', 'string', 200); - $this->hasColumn('child_id', 'integer'); - } - public function setUp() { - - $this->hasMany('RTC1 as RTC1', 'JC1.c1_id'); - $this->hasMany('RTC2 as RTC2', 'JC1.c1_id'); - $this->hasMany('RTC3 as RTC3', 'JC2.c1_id'); - $this->hasMany('RTC3 as RTC4', 'JC1.c1_id'); - + public static function initMetadata($class) { + $class->setColumn('name', 'string', 200); + $class->setColumn('child_id', 'integer'); + $class->hasMany('RTC1 as RTC1', array('local' => 'c2_id', 'foreign' => 'c1_id', 'refClass' => 'JC1')); + $class->hasMany('RTC2 as RTC2', array('local' => 'c2_id', 'foreign' => 'c1_id', 'refClass' => 'JC1')); + $class->hasMany('RTC3 as RTC3', array('local' => 'c2_id', 'foreign' => 'c1_id', 'refClass' => 'JC2')); + $class->hasMany('RTC3 as RTC4', array('local' => 'c2_id', 'foreign' => 'c1_id', 'refClass' => 'c1_id')); } } diff --git a/models/M2MTest2.php b/models/M2MTest2.php index ce4cdf6c3..c39b28e19 100644 --- a/models/M2MTest2.php +++ b/models/M2MTest2.php @@ -1,11 +1,9 @@ hasColumn('oid', 'integer', 11, array('autoincrement', 'primary')); - $this->hasColumn('name', 'string', 20); - } - public function setUp() { - $this->hasMany('RTC4 as RTC5', 'JC3.c1_id'); + public static function initMetadata($class) { + $class->setColumn('oid', 'integer', 11, array('autoincrement', 'primary')); + $class->setColumn('name', 'string', 20); + $class->hasMany('RTC4 as RTC5', array('local' => 'c2_id', 'foreign' => 'c1_id', 'refClass' => 'JC1')); } } diff --git a/models/MigrationTest.php b/models/MigrationTest.php index f042df011..72023b1ff 100644 --- a/models/MigrationTest.php +++ b/models/MigrationTest.php @@ -1,8 +1,8 @@ hasColumn('field1', 'string'); + $class->setColumn('field1', 'string'); } } \ No newline at end of file diff --git a/models/MyUserOneThing.php b/models/MyUserOneThing.php index b681043d0..a91953fe2 100644 --- a/models/MyUserOneThing.php +++ b/models/MyUserOneThing.php @@ -1,7 +1,7 @@ hasColumn('user_id', 'integer'); - $this->hasColumn('one_thing_id', 'integer'); + public static function initMetadata($class) { + $class->setColumn('user_id', 'integer'); + $class->setColumn('one_thing_id', 'integer'); } } diff --git a/models/MysqlGroup.php b/models/MysqlGroup.php index cccae6325..acc7d81eb 100644 --- a/models/MysqlGroup.php +++ b/models/MysqlGroup.php @@ -1,10 +1,9 @@ hasColumn('name', 'string', null); - - $this->hasMany('MysqlUser', 'MysqlGroupMember.user_id'); + $class->setColumn('name', 'string', null); + $class->hasMany('MysqlUser', array('local' => 'id', 'foreign' => 'user_id')); } } diff --git a/models/MysqlIndexTestRecord.php b/models/MysqlIndexTestRecord.php index cc2dd8630..3b7bd3c5a 100644 --- a/models/MysqlIndexTestRecord.php +++ b/models/MysqlIndexTestRecord.php @@ -1,17 +1,17 @@ hasColumn('name', 'string', null); - $this->hasColumn('code', 'integer', 4); - $this->hasColumn('content', 'string', 4000); + $class->setColumn('name', 'string', null); + $class->setColumn('code', 'integer', 4); + $class->setColumn('content', 'string', 4000); - $this->index('content', array('fields' => 'content', 'type' => 'fulltext')); - $this->index('namecode', array('fields' => array('name', 'code'), + $class->addIndex('content', array('fields' => 'content', 'type' => 'fulltext')); + $class->addIndex('namecode', array('fields' => array('name', 'code'), 'type' => 'unique')); - $this->option('type', 'MYISAM'); + $class->setTableOption('type', 'MYISAM'); } } diff --git a/models/MysqlTestRecord.php b/models/MysqlTestRecord.php index 44bd8f582..3b4d094cc 100644 --- a/models/MysqlTestRecord.php +++ b/models/MysqlTestRecord.php @@ -1,11 +1,11 @@ hasColumn('name', 'string', null, 'primary'); - $this->hasColumn('code', 'integer', null, 'primary'); + $class->setColumn('name', 'string', null, 'primary'); + $class->setColumn('code', 'integer', null, 'primary'); - $this->option('type', 'INNODB'); + $class->setTableOption('type', 'INNODB'); } } diff --git a/models/MysqlUser.php b/models/MysqlUser.php index 2b4981ce7..d66d48601 100644 --- a/models/MysqlUser.php +++ b/models/MysqlUser.php @@ -1,10 +1,9 @@ hasColumn('name', 'string', null); - - $this->hasMany('MysqlGroup', 'MysqlGroupMember.group_id'); + $class->setColumn('name', 'string', null); + $class->hasMany('MysqlGroup', array('local' => 'id', 'foreign' => 'group_id')); } } diff --git a/models/NestReference.php b/models/NestReference.php index 0f2d05888..d05aace07 100644 --- a/models/NestReference.php +++ b/models/NestReference.php @@ -1,9 +1,9 @@ hasColumn('parent_id', 'integer', 4, 'primary'); - $this->hasColumn('child_id', 'integer', 4, 'primary'); + $class->setColumn('parent_id', 'integer', 4, 'primary'); + $class->setColumn('child_id', 'integer', 4, 'primary'); } } diff --git a/models/NestTest.php b/models/NestTest.php index f1bdea67a..08666ec8b 100644 --- a/models/NestTest.php +++ b/models/NestTest.php @@ -1,20 +1,17 @@ hasColumn('name', 'string'); - } - public function setUp() - { - $this->hasMany('NestTest as Parents', array('local' => 'child_id', + $class->setColumn('name', 'string'); + $class->hasMany('NestTest as Parents', array('local' => 'child_id', 'refClass' => 'NestReference', 'foreign' => 'parent_id')); - $this->hasMany('NestTest as Children', array('local' => 'parent_id', + $class->hasMany('NestTest as Children', array('local' => 'parent_id', 'refClass' => 'NestReference', 'foreign' => 'child_id')); - $this->hasMany('NestTest as Relatives', array('local' => 'child_id', + $class->hasMany('NestTest as Relatives', array('local' => 'child_id', 'refClass' => 'NestReference', 'foreign' => 'parent_id', 'equal' => true)); diff --git a/models/NestedSetTest_SingleRootNode.php b/models/NestedSetTest_SingleRootNode.php index 1aea10b8f..b9540b81a 100644 --- a/models/NestedSetTest_SingleRootNode.php +++ b/models/NestedSetTest_SingleRootNode.php @@ -1,9 +1,9 @@ actAs('NestedSet'); - $this->hasColumn('name', 'string', 50, array('notnull')); + public static function initMetadata($class) { + $class->actAs('NestedSet'); + $class->setColumn('name', 'string', 50, array('notnull')); } } diff --git a/models/NotNullTest.php b/models/NotNullTest.php index 786d213a2..733f128e0 100644 --- a/models/NotNullTest.php +++ b/models/NotNullTest.php @@ -1,7 +1,7 @@ hasColumn('name', 'string', 100, 'notnull'); - $this->hasColumn('type', 'integer', 11); + public static function initMetadata($class) { + $class->setColumn('name', 'string', 100, 'notnull'); + $class->setColumn('type', 'integer', 11); } } diff --git a/models/ORM_AccessControl.php b/models/ORM_AccessControl.php index f1cbb1bd3..9442d8789 100644 --- a/models/ORM_AccessControl.php +++ b/models/ORM_AccessControl.php @@ -1,12 +1,12 @@ hasColumn('name', 'string', 255); - } - public function setUp() - { - $this->hasMany('ORM_AccessGroup as accessGroups', 'ORM_AccessControlsGroups.accessGroupID'); + $class->setColumn('name', 'string', 255); + $class->hasMany('ORM_AccessGroup as accessGroups', array( + 'local' => 'accessControlID', 'foreign' => 'accessGroupID', + 'refClass' => 'ORM_AccessControlsGroups') + ); } } diff --git a/models/ORM_AccessControlsGroups.php b/models/ORM_AccessControlsGroups.php index 218b219c3..ba0792ac8 100644 --- a/models/ORM_AccessControlsGroups.php +++ b/models/ORM_AccessControlsGroups.php @@ -1,9 +1,9 @@ hasColumn('accessControlID', 'integer', 11, array('primary' => true)); - $this->hasColumn('accessGroupID', 'integer', 11, array('primary' => true)); + $class->setColumn('accessControlID', 'integer', 11, array('primary' => true)); + $class->setColumn('accessGroupID', 'integer', 11, array('primary' => true)); } } diff --git a/models/ORM_AccessGroup.php b/models/ORM_AccessGroup.php index ac824259f..948092427 100644 --- a/models/ORM_AccessGroup.php +++ b/models/ORM_AccessGroup.php @@ -1,12 +1,11 @@ hasColumn('name', 'string', 255); - } - public function setUp() - { - $this->hasMany('ORM_AccessControl as accessControls', 'ORM_AccessControlsGroups.accessControlID'); + $class->setColumn('name', 'string', 255); + $class->hasMany('ORM_AccessControl as accessControls', + array('local' => 'accessGroupID', 'foreign' => 'accessControlID', + 'refClass' => 'ORM_AccessControlsGroups')); } } diff --git a/models/Package.php b/models/Package.php index a5b5e5f7d..fda314f3d 100644 --- a/models/Package.php +++ b/models/Package.php @@ -1,11 +1,7 @@ hasColumn('description', 'string', 255); - } - - public function setUp() - { - $this->hasMany('PackageVersion as Version', 'PackageVersion.package_id'); + public static function initMetadata($class) { + $class->setColumn('description', 'string', 255); + $class->hasMany('PackageVersion as Version', array('local' => 'id', 'foreign' => 'package_id')); } } diff --git a/models/Page.php b/models/Page.php index 02f00fc42..b8a88bd4e 100644 --- a/models/Page.php +++ b/models/Page.php @@ -2,16 +2,12 @@ class Page extends Doctrine_Record { - public function setUp() + public static function initMetadata($class) { - $this->hasMany('Bookmark as Bookmarks', + $class->setColumn('name', 'string', 30); + $class->setColumn('url', 'string', 100); + $class->hasMany('Bookmark as Bookmarks', array('local' => 'id', 'foreign' => 'page_id')); } - - public function setTableDefinition() - { - $this->hasColumn('name', 'string', 30); - $this->hasColumn('url', 'string', 100); - } } diff --git a/models/Phonenumber.php b/models/Phonenumber.php index 23b178dc4..195e89a73 100644 --- a/models/Phonenumber.php +++ b/models/Phonenumber.php @@ -1,22 +1,20 @@ hasColumn('phonenumber', 'string',20); - $this->hasColumn('entity_id', 'integer'); - } - public function setUp() - { - $this->hasOne('Entity', array('local' => 'entity_id', + $class->setColumn('phonenumber', 'string',20); + $class->setColumn('entity_id', 'integer'); + + $class->hasOne('Entity', array('local' => 'entity_id', 'foreign' => 'id', 'onDelete' => 'CASCADE')); - $this->hasOne('Group', array('local' => 'entity_id', + $class->hasOne('Group', array('local' => 'entity_id', 'foreign' => 'id', 'onDelete' => 'CASCADE')); - $this->hasOne('User', array('local' => 'entity_id', + $class->hasOne('User', array('local' => 'entity_id', 'foreign' => 'id', 'onDelete' => 'CASCADE')); } diff --git a/models/Photo.php b/models/Photo.php index 62fd4c972..ea2dc1992 100644 --- a/models/Photo.php +++ b/models/Photo.php @@ -1,9 +1,7 @@ hasMany('Tag', 'Phototag.tag_id'); - } - public function setTableDefinition() { - $this->hasColumn('name', 'string', 100); + public static function initMetadata($class) { + $class->setColumn('name', 'string', 100); + $class->hasMany('Tag', array('local' => 'photo_id', 'foreign' => 'tag_id', 'refClass' => 'Phototag')); } } diff --git a/models/Phototag.php b/models/Phototag.php index cb1aaab14..c7a97e0e2 100644 --- a/models/Phototag.php +++ b/models/Phototag.php @@ -1,7 +1,7 @@ hasColumn('photo_id', 'integer'); - $this->hasColumn('tag_id', 'integer'); + public static function initMetadata($class) { + $class->setColumn('photo_id', 'integer'); + $class->setColumn('tag_id', 'integer'); } } diff --git a/models/PluginSymfonyRecordTable.php b/models/PluginSymfonyRecordTable.php index b24d10ddc..2be320316 100644 --- a/models/PluginSymfonyRecordTable.php +++ b/models/PluginSymfonyRecordTable.php @@ -1,5 +1,5 @@ hasColumn('policy_number', 'integer', 11, array('unique' => true)); + $class->setColumn('policy_number', 'integer', 11, array('unique' => true)); + $class->hasMany('PolicyAsset as PolicyAssets', array('local' => 'policy_number', + 'foreign' => 'policy_number')); + $class->addIndex('policy_number_index', array('fields' => array('policy_number'))); } - public function setUp() - { - $this->hasMany('PolicyAsset as PolicyAssets', array('local' => 'policy_number', - 'foreign' => 'policy_number')); - $this->index('policy_number_index', array('fields' => array('policy_number'))); - } } diff --git a/models/PolicyAsset.php b/models/PolicyAsset.php index f68da7a02..bac662615 100644 --- a/models/PolicyAsset.php +++ b/models/PolicyAsset.php @@ -1,16 +1,12 @@ hasColumn('policy_number', 'integer', 11); - $this->hasColumn('value', 'float', 10, array ('notblank' => true,)); - } - - public function setUp() - { - $this->hasOne('Policy', array('foreign' => 'policy_number', + $class->setColumn('policy_number', 'integer', 11); + $class->setColumn('value', 'float', 10, array ('notblank' => true,)); + $class->hasOne('Policy', array('foreign' => 'policy_number', 'local' => 'policy_number')); - $this->index('policy_number_index', array('fields' => array('policy_number'))); + $class->addIndex('policy_number_index', array('fields' => array('policy_number'))); } } diff --git a/models/PolicyCodeN.php b/models/PolicyCodeN.php index 1d3df65fa..cd747c265 100644 --- a/models/PolicyCodeN.php +++ b/models/PolicyCodeN.php @@ -1,14 +1,10 @@ setTableName('policy_codes'); - $this->hasColumn('id', 'integer', 4, array('notnull' => true, 'primary' => true, 'autoincrement' => true)); - $this->hasColumn('code', 'integer', 4, array ( 'notnull' => true, 'notblank' => true,)); - $this->hasColumn('description', 'string', 4000, array ( 'notnull' => true, 'notblank' => true,)); + public static function initMetadata($class) { + $class->setTableName('policy_codes'); + $class->setColumn('id', 'integer', 4, array('notnull' => true, 'primary' => true, 'autoincrement' => true)); + $class->setColumn('code', 'integer', 4, array ( 'notnull' => true, 'notblank' => true,)); + $class->setColumn('description', 'string', 4000, array ( 'notnull' => true, 'notblank' => true,)); } - - public function setUp(){ -# $this->index('code', array('fields' => 'code')); - } } diff --git a/models/PolicyN.php b/models/PolicyN.php index dc8cf95b2..11e10617d 100644 --- a/models/PolicyN.php +++ b/models/PolicyN.php @@ -1,15 +1,12 @@ setTableName('policies'); - $this->hasColumn('id', 'integer', 4, array('notnull' => true, 'primary' => true, 'autoincrement' => true)); - $this->hasColumn('rate_id', 'integer', 4, array ( )); - $this->hasColumn('policy_number', 'integer', 4, array ( 'unique' => true, )); - } - - public function setUp(){ - $this->hasOne('RateN', array('local' => 'rate_id', 'foreign' => 'id' )); + public static function initMetadata($class) { + $class->setTableName('policies'); + $class->setColumn('id', 'integer', 4, array('notnull' => true, 'primary' => true, 'autoincrement' => true)); + $class->setColumn('rate_id', 'integer', 4, array ( )); + $class->setColumn('policy_number', 'integer', 4, array ( 'unique' => true, )); + $class->hasOne('RateN', array('local' => 'rate_id', 'foreign' => 'id' )); } } diff --git a/models/QueryTest_Board.php b/models/QueryTest_Board.php index 6a5fad158..9b730ff47 100644 --- a/models/QueryTest_Board.php +++ b/models/QueryTest_Board.php @@ -4,24 +4,18 @@ class QueryTest_Board extends Doctrine_Record /** * Initializes the table definition. */ - public function setTableDefinition() + public static function initMetadata($class) { - $this->hasColumn('categoryId as categoryId', 'integer', 4, + $class->setColumn('categoryId as categoryId', 'integer', 4, array('notnull')); - $this->hasColumn('name as name', 'string', 100, + $class->setColumn('name as name', 'string', 100, array('notnull', 'unique')); - $this->hasColumn('lastEntryId as lastEntryId', 'integer', 4, + $class->setColumn('lastEntryId as lastEntryId', 'integer', 4, array('default' => 0, 'notnull')); - $this->hasColumn('position as position', 'integer', 4, + $class->setColumn('position as position', 'integer', 4, array('default' => 0, 'notnull')); - } - - /** - * Initializes the relations. - */ - public function setUp() - { - $this->hasOne('QueryTest_Category as category', 'QueryTest_Board.categoryId'); - $this->hasOne('QueryTest_Entry as lastEntry', 'QueryTest_Board.lastEntryId'); + + $class->hasOne('QueryTest_Category as category', array('local' => 'categoryId', 'foreign' => 'id')); + $class->hasOne('QueryTest_Entry as lastEntry', array('local' => 'lastEntryId', 'foreign' => 'id')); } } diff --git a/models/QueryTest_Category.php b/models/QueryTest_Category.php index 8c432d6db..30e1cb9b5 100644 --- a/models/QueryTest_Category.php +++ b/models/QueryTest_Category.php @@ -12,25 +12,19 @@ class QueryTest_Category extends Doctrine_Record /** * Table definition. */ - public function setTableDefinition() + public static function initMetadata($class) { - $this->hasColumn('rootCategoryId as rootCategoryId', 'integer', 4, + $class->setColumn('rootCategoryId as rootCategoryId', 'integer', 4, array('default' => 0)); - $this->hasColumn('parentCategoryId as parentCategoryId', 'integer', 4, + $class->setColumn('parentCategoryId as parentCategoryId', 'integer', 4, array('notnull', 'default' => 0)); - $this->hasColumn('name as name', 'string', 50, + $class->setColumn('name as name', 'string', 50, array('notnull', 'unique')); - $this->hasColumn('position as position', 'integer', 4, + $class->setColumn('position as position', 'integer', 4, array('default' => 0, 'notnull')); - } - - /** - * Relations definition. - */ - public function setUp() - { - $this->hasMany('QueryTest_Category as subCategories', 'subCategories.parentCategoryId'); - $this->hasOne('QueryTest_Category as rootCategory', 'QueryTest_Category.rootCategoryId'); - $this->hasMany('QueryTest_Board as boards', 'QueryTest_Board.categoryId'); + + $class->hasMany('QueryTest_Category as subCategories', array('local' => 'id', 'foreign' => 'parentCategoryId')); + $class->hasOne('QueryTest_Category as rootCategory', array('local' => 'rootCategoryId', 'foreign' => 'id')); + $class->hasMany('QueryTest_Board as boards', array('local' => 'id', 'foreign' => 'categoryId')); } } diff --git a/models/QueryTest_Entry.php b/models/QueryTest_Entry.php index 1f8321e0a..95f49ae2b 100644 --- a/models/QueryTest_Entry.php +++ b/models/QueryTest_Entry.php @@ -4,19 +4,12 @@ class QueryTest_Entry extends Doctrine_Record /** * Table structure. */ - public function setTableDefinition() + public static function initMetadata($class) { - $this->hasColumn('authorId', 'integer', 4, + $class->setColumn('authorId', 'integer', 4, array('notnull')); - $this->hasColumn('date', 'integer', 4, + $class->setColumn('date', 'integer', 4, array('notnull')); - } - - /** - * Runtime definition of the relationships to other entities. - */ - public function setUp() - { - $this->hasOne('QueryTest_User as author', 'QueryTest_Entry.authorId'); + $class->hasOne('QueryTest_User as author', array('local' => 'authorId', 'foreign' => 'id')); } } diff --git a/models/QueryTest_Item.php b/models/QueryTest_Item.php index 797f4c04f..8680fe6ad 100644 --- a/models/QueryTest_Item.php +++ b/models/QueryTest_Item.php @@ -1,10 +1,10 @@ hasColumn('price', 'decimal'); - $this->hasColumn('quantity', 'integer'); + $class->setColumn('price', 'decimal'); + $class->setColumn('quantity', 'integer'); } } diff --git a/models/QueryTest_Rank.php b/models/QueryTest_Rank.php index bbe24328d..02ff3fd42 100644 --- a/models/QueryTest_Rank.php +++ b/models/QueryTest_Rank.php @@ -4,17 +4,15 @@ class QueryTest_Rank extends Doctrine_Record /** * Initializes the table definition. */ - public function setTableDefinition() + public static function initMetadata($class) { - $this->hasColumn('title as title', 'string', 100, + $class->setColumn('title as title', 'string', 100, array('notnull')); - $this->hasColumn('color as color', 'string', 20, + $class->setColumn('color as color', 'string', 20, array('notnull', 'regexp' => '/^[a-zA-Z\-]{3,}|#[0-9a-fA-F]{6}$/D')); - $this->hasColumn('icon as icon', 'string', 50, - array('notnull', 'default' => ' ', 'regexp' => '/^[a-zA-Z0-9_\-]+\.(jpg|gif|png)$/D')); - } - public function setUp() - { - $this->hasMany('QueryTest_User as users', 'QueryTest_UserRank.userId'); + $class->setColumn('icon as icon', 'string', 50, + array('notnull', 'default' => ' ', 'regexp' => '/^[a-zA-Z0-9_\-]+\.(jpg|gif|png)$/D')); + + $class->hasMany('QueryTest_User as users', array('local' => 'rankId', 'foreign' => 'userId', 'refClass' => 'QueryTest_UserRank')); } } diff --git a/models/QueryTest_User.php b/models/QueryTest_User.php index 7727360a0..696398e07 100644 --- a/models/QueryTest_User.php +++ b/models/QueryTest_User.php @@ -2,19 +2,12 @@ class QueryTest_User extends Doctrine_Record { - public function setTableDefinition() + public static function initMetadata($class) { - $this->hasColumn('username as username', 'string', 50, + $class->setColumn('username as username', 'string', 50, array('notnull')); - $this->hasColumn('visibleRankId', 'integer', 4); - } - - /** - * Runtime definition of the relationships to other entities. - */ - public function setUp() - { - $this->hasOne('QueryTest_Rank as visibleRank', 'QueryTest_User.visibleRankId'); - $this->hasMany('QueryTest_Rank as ranks', 'QueryTest_UserRank.rankId'); + $class->setColumn('visibleRankId', 'integer', 4); + $class->hasOne('QueryTest_Rank as visibleRank', array('local' => 'visibleRankId', 'foreign' => 'id')); + $class->hasMany('QueryTest_Rank as ranks', array('local' => 'userId', 'foreign' => 'rankId', 'refClass' => 'QueryTest_UserRank')); } } diff --git a/models/QueryTest_UserRank.php b/models/QueryTest_UserRank.php index 9f9d75b7e..c69449113 100644 --- a/models/QueryTest_UserRank.php +++ b/models/QueryTest_UserRank.php @@ -1,9 +1,9 @@ hasColumn('rankId', 'integer', 4, array('primary')); - $this->hasColumn('userId', 'integer', 4, array('primary')); + $class->setColumn('rankId', 'integer', 4, array('primary')); + $class->setColumn('userId', 'integer', 4, array('primary')); } } diff --git a/models/RTC4.php b/models/RTC4.php index 12461b851..cbc1353ce 100644 --- a/models/RTC4.php +++ b/models/RTC4.php @@ -1,10 +1,8 @@ hasColumn('oid', 'integer', 11, array('autoincrement', 'primary')); - $this->hasColumn('name', 'string', 20); - } - public function setUp() { - $this->hasMany('M2MTest2', 'JC3.c2_id'); + public static function initMetadata($class) { + $class->setColumn('oid', 'integer', 11, array('autoincrement', 'primary')); + $class->setColumn('name', 'string', 20); + $class->hasMany('M2MTest2', array('local' => 'c1_id', 'foreign' => 'c2_id', 'refClass' => 'JC3')); } } diff --git a/models/RateN.php b/models/RateN.php index f2adbb48d..c2db3ae65 100644 --- a/models/RateN.php +++ b/models/RateN.php @@ -1,22 +1,16 @@ setTableName('rates'); - $this->hasColumn('id', 'integer', 4, array('notnull' => true, 'primary' => true, 'autoincrement' => true)); - $this->hasColumn('policy_code', 'integer', 4, array ( 'notnull' => true, 'notblank' => true,)); - $this->hasColumn('coverage_code', 'integer', 4, array ( 'notnull' => true, 'notblank' => true,)); - $this->hasColumn('liability_code', 'integer', 4, array ( 'notnull' => true, 'notblank' => true,)); - $this->hasColumn('total_rate', 'float', null, array ( 'notnull' => true, 'notblank' => true,)); - } - - public function setUp(){ -# $this->index('policy_code_idx', array('fields' => 'policy_code')); -# $this->index('coverage_code_idx', array('fields' => 'coverage_code')); -# $this->index('liability_code_idx', array('fields' => 'liability_code')); - $this->hasOne('PolicyCodeN', array('local' => 'policy_code', 'foreign' => 'code' )); - $this->hasOne('CoverageCodeN', array('local' => 'coverage_code', 'foreign' => 'code' )); - $this->hasOne('LiabilityCodeN', array('local' => 'liability_code', 'foreign' => 'code' )); + public static function initMetadata($class) { + $class->setTableName('rates'); + $class->setColumn('id', 'integer', 4, array('notnull' => true, 'primary' => true, 'autoincrement' => true)); + $class->setColumn('policy_code', 'integer', 4, array ( 'notnull' => true, 'notblank' => true,)); + $class->setColumn('coverage_code', 'integer', 4, array ( 'notnull' => true, 'notblank' => true,)); + $class->setColumn('liability_code', 'integer', 4, array ( 'notnull' => true, 'notblank' => true,)); + $class->setColumn('total_rate', 'float', null, array ( 'notnull' => true, 'notblank' => true,)); + $class->hasOne('PolicyCodeN', array('local' => 'policy_code', 'foreign' => 'code' )); + $class->hasOne('CoverageCodeN', array('local' => 'coverage_code', 'foreign' => 'code' )); + $class->hasOne('LiabilityCodeN', array('local' => 'liability_code', 'foreign' => 'code' )); } } diff --git a/models/Rec1.php b/models/Rec1.php index 52dd07546..7ca223d3b 100644 --- a/models/Rec1.php +++ b/models/Rec1.php @@ -1,14 +1,10 @@ hasColumn('first_name', 'string', 128, array ()); - } - - public function setUp() - { - $this->hasOne('Rec2 as Account', array('local' => 'id', 'foreign' => 'user_id')); + $class->setColumn('first_name', 'string', 128, array ()); + $class->hasOne('Rec2 as Account', array('local' => 'id', 'foreign' => 'user_id')); } } diff --git a/models/Rec2.php b/models/Rec2.php index 02341f607..a46561562 100644 --- a/models/Rec2.php +++ b/models/Rec2.php @@ -1,15 +1,10 @@ hasColumn('user_id', 'integer', 10, array ( 'unique' => true,)); - $this->hasColumn('address', 'string', 150, array ()); + $class->setColumn('user_id', 'integer', 10, array ( 'unique' => true,)); + $class->setColumn('address', 'string', 150, array ()); + $class->hasOne('Rec1 as User', array('local' => 'user_id', 'foreign' => 'id')); } - - public function setUp() - { - $this->hasOne('Rec1 as User', 'Rec2.user_id'); - } - } diff --git a/models/RecordFilterTest.php b/models/RecordFilterTest.php index 521448d34..411c29911 100644 --- a/models/RecordFilterTest.php +++ b/models/RecordFilterTest.php @@ -1,11 +1,10 @@ hasColumn("name", "string", 200); - $this->hasColumn("password", "string", 32); + $class->setColumn("name", "string", 200); + $class->setColumn("password", "string", 32); } public function setPassword($password) { return md5($password); diff --git a/models/RecordHookTest.php b/models/RecordHookTest.php index b725cb1a4..84314b01f 100644 --- a/models/RecordHookTest.php +++ b/models/RecordHookTest.php @@ -3,39 +3,39 @@ class RecordHookTest extends Doctrine_Record { protected $_messages = array(); - public function setTableDefinition() + public static function initMetadata($class) { - $this->hasColumn('name', 'string', null, array('primary' => true)); + $class->setColumn('name', 'string', null, array('primary' => true)); } - public function preSave($event) + public function preSave(Doctrine_Event $event) { $this->_messages[] = __FUNCTION__; } - public function postSave($event) + public function postSave(Doctrine_Event $event) { $this->_messages[] = __FUNCTION__; } - public function preInsert($event) + public function preInsert(Doctrine_Event $event) { $this->_messages[] = __FUNCTION__; } - public function postInsert($event) + public function postInsert(Doctrine_Event $event) { $this->_messages[] = __FUNCTION__; } - public function preUpdate($event) + public function preUpdate(Doctrine_Event $event) { $this->_messages[] = __FUNCTION__; } - public function postUpdate($event) + public function postUpdate(Doctrine_Event $event) { $this->_messages[] = __FUNCTION__; } - public function preDelete($event) + public function preDelete(Doctrine_Event $event) { $this->_messages[] = __FUNCTION__; } - public function postDelete($event) + public function postDelete(Doctrine_Event $event) { $this->_messages[] = __FUNCTION__; } diff --git a/models/Record_City.php b/models/Record_City.php index 3259fb9b4..a1937d6f6 100644 --- a/models/Record_City.php +++ b/models/Record_City.php @@ -1,12 +1,10 @@ hasColumn('name', 'string', 200); - $this->hasColumn('country_id', 'integer'); - $this->hasColumn('district_id', 'integer'); - } - public function setUp() { - $this->hasOne('Record_Country as Country', 'Record_City.country_id'); - $this->hasOne('Record_District as District', 'Record_City.district_id'); + public static function initMetadata($class) { + $class->setColumn('name', 'string', 200); + $class->setColumn('country_id', 'integer'); + $class->setColumn('district_id', 'integer'); + $class->hasOne('Record_Country as Country', array('local' => 'country_id', 'foreign' => 'id')); + $class->hasOne('Record_District as District', array('local' => 'district_id', 'foreign' => 'id')); } } diff --git a/models/Record_Country.php b/models/Record_Country.php index c6f873bea..5cc0e9cdc 100644 --- a/models/Record_Country.php +++ b/models/Record_Country.php @@ -1,10 +1,8 @@ hasColumn('name', 'string', 200); - } - public function setUp() { - $this->hasMany('Record_City as City', 'City.country_id'); + public static function initMetadata($class) { + $class->setColumn('name', 'string', 200); + $class->hasMany('Record_City as City', array('local' => 'id', 'foreign' => 'country_id')); } } diff --git a/models/Record_District.php b/models/Record_District.php index a56ccf8b3..69fc91371 100644 --- a/models/Record_District.php +++ b/models/Record_District.php @@ -1,6 +1,6 @@ hasColumn('name', 'string', 200); + public static function initMetadata($class) { + $class->setColumn('name', 'string', 200); } } diff --git a/models/RelationTest.php b/models/RelationTest.php index 2932d7ca0..5d76dd1c3 100644 --- a/models/RelationTest.php +++ b/models/RelationTest.php @@ -1,23 +1,23 @@ hasColumn('name', 'string', 200); - $this->hasColumn('parent_id', 'integer'); + $class->setColumn('name', 'string', 200); + $class->setColumn('parent_id', 'integer'); } } class RelationTestChild extends RelationTest { - public function setUp() + public static function initMetadata($class) { - $this->hasOne('RelationTest as Parent', array( + $class->hasOne('RelationTest as Parent', array( 'local' => 'parent_id', 'foreign' => 'id', 'onDelete' => 'CASCADE', )); - $this->hasMany('RelationTestChild as Children', array( + $class->hasMany('RelationTestChild as Children', array( 'local' => 'id', 'foreign' => 'parent_id', )); diff --git a/models/Resource.php b/models/Resource.php index cb91c5e41..353d991d9 100644 --- a/models/Resource.php +++ b/models/Resource.php @@ -1,10 +1,8 @@ hasMany('Task as TaskAlias', 'Assignment.task_id'); - $this->hasMany('ResourceType as Type', 'ResourceReference.type_id'); - } - public function setTableDefinition() { - $this->hasColumn('name', 'string',100); + public static function initMetadata($class) { + $class->setColumn('name', 'string',100); + $class->hasMany('Task as TaskAlias', array('local' => 'resource_id', 'foreign' => 'task_id', 'refClass' => 'Assignment')); + $class->hasMany('ResourceType as Type', array('local' => 'resource_id', 'foreign' => 'type_id', 'refClass' => 'ResourceReference')); } } diff --git a/models/ResourceReference.php b/models/ResourceReference.php index aec7795b2..a38a2af0e 100644 --- a/models/ResourceReference.php +++ b/models/ResourceReference.php @@ -1,8 +1,8 @@ hasColumn('type_id', 'integer'); - $this->hasColumn('resource_id', 'integer'); + public static function initMetadata($class) { + $class->setColumn('type_id', 'integer'); + $class->setColumn('resource_id', 'integer'); } } diff --git a/models/ResourceType.php b/models/ResourceType.php index 9dfb9c2b2..44405beb6 100644 --- a/models/ResourceType.php +++ b/models/ResourceType.php @@ -1,10 +1,8 @@ hasMany('Resource as ResourceAlias', 'ResourceReference.resource_id'); - } - public function setTableDefinition() { - $this->hasColumn('type', 'string',100); + public static function initMetadata($class) { + $class->setColumn('type', 'string',100); + $class->hasMany('Resource as ResourceAlias', array('local' => 'type_id', 'foreign' => 'resource_id', 'refClass' => 'ResourceReference')); } } diff --git a/models/Role.php b/models/Role.php index 44e46e9a6..c7a667bca 100644 --- a/models/Role.php +++ b/models/Role.php @@ -1,13 +1,11 @@ hasColumn('name', 'string', 20, array('unique' => true)); - } - public function setUp() - { - $this->hasMany('Auth', array('local' => 'id', 'foreign' => 'roleid')); + $class->setColumn('name', 'string', 20, array('unique' => true)); + $class->hasMany('Auth', array('local' => 'id', 'foreign' => 'roleid')); } + } diff --git a/models/SearchTest.php b/models/SearchTest.php index 38fbfe719..8a37b726a 100644 --- a/models/SearchTest.php +++ b/models/SearchTest.php @@ -1,16 +1,12 @@ hasColumn('title', 'string', 100); - $this->hasColumn('content', 'string'); - } - public function setUp() - { - $options = array('generateFiles' => false, + $class->setColumn('title', 'string', 100); + $class->setColumn('content', 'string'); + $options = array('generateFiles' => false, 'fields' => array('title', 'content')); - - $this->actAs('Searchable', $options); + $class->actAs('Searchable', $options); } } diff --git a/models/SelfRefTest.php b/models/SelfRefTest.php index fdf9dd3e1..22e3dd1f3 100644 --- a/models/SelfRefTest.php +++ b/models/SelfRefTest.php @@ -1,14 +1,11 @@ hasColumn('name', 'string', 50); - $this->hasColumn('created_by', 'integer'); - } - public function setUp() - { - $this->hasOne('SelfRefTest as createdBy', array('local' => 'created_by')); + $class->setColumn('name', 'string', 50); + $class->setColumn('created_by', 'integer'); + $class->hasOne('SelfRefTest as createdBy', array('local' => 'created_by')); } } diff --git a/models/SerializeTest.php b/models/SerializeTest.php index cc16ec4c1..9401e9d93 100644 --- a/models/SerializeTest.php +++ b/models/SerializeTest.php @@ -1,22 +1,22 @@ setTableName('serialize_test'); + $class->setTableName('serialize_test'); - $this->hasColumn('booltest', 'boolean'); - $this->hasColumn('integertest', 'integer', 4, array('unsigned' => true)); - $this->hasColumn('floattest', 'float'); - $this->hasColumn('stringtest', 'string', 200, array('fixed' => true)); - $this->hasColumn('arraytest', 'array', 10000); - $this->hasColumn('objecttest', 'object'); - $this->hasColumn('blobtest', 'blob'); - $this->hasColumn('clobtest', 'clob'); - $this->hasColumn('timestamptest', 'timestamp'); - $this->hasColumn('timetest', 'time'); - $this->hasColumn('datetest', 'date'); - $this->hasColumn('enumtest', 'enum', 4, + $class->setColumn('booltest', 'boolean'); + $class->setColumn('integertest', 'integer', 4, array('unsigned' => true)); + $class->setColumn('floattest', 'float'); + $class->setColumn('stringtest', 'string', 200, array('fixed' => true)); + $class->setColumn('arraytest', 'array', 10000); + $class->setColumn('objecttest', 'object'); + $class->setColumn('blobtest', 'blob'); + $class->setColumn('clobtest', 'clob'); + $class->setColumn('timestamptest', 'timestamp'); + $class->setColumn('timetest', 'time'); + $class->setColumn('datetest', 'date'); + $class->setColumn('enumtest', 'enum', 4, array( 'values' => array( 'php', @@ -25,7 +25,7 @@ class SerializeTest extends Doctrine_Record ) ) ); - $this->hasColumn('gziptest', 'gzip'); + $class->setColumn('gziptest', 'gzip'); } } diff --git a/models/SoftDeleteTest.php b/models/SoftDeleteTest.php index ed7aba62a..6644dbc26 100644 --- a/models/SoftDeleteTest.php +++ b/models/SoftDeleteTest.php @@ -1,17 +1,17 @@ hasColumn('name', 'string', null, array('primary' => true)); - $this->hasColumn('something', 'string', '25', array('notnull' => true, 'unique' => true)); - $this->hasColumn('deleted', 'boolean', 1); + $class->setColumn('name', 'string', null, array('primary' => true)); + $class->setColumn('something', 'string', '25', array('notnull' => true, 'unique' => true)); + $class->setColumn('deleted', 'boolean', 1); } - public function preDelete($event) + public function preDelete(Doctrine_Event $event) { $event->skipOperation(); } - public function postDelete($event) + public function postDelete(Doctrine_Event $event) { $this->deleted = true; diff --git a/models/Song.php b/models/Song.php index b9df96689..de0c66ee2 100644 --- a/models/Song.php +++ b/models/Song.php @@ -1,16 +1,13 @@ hasOne('Album', array('local' => 'album_id', + $class->setColumn('album_id', 'integer'); + $class->setColumn('genre', 'string',20); + $class->setColumn('title', 'string',30); + $class->hasOne('Album', array('local' => 'album_id', 'foreign' => 'id', 'onDelete' => 'CASCADE')); } - public function setTableDefinition() - { - $this->hasColumn('album_id', 'integer'); - $this->hasColumn('genre', 'string',20); - $this->hasColumn('title', 'string',30); - } } diff --git a/models/Tag.php b/models/Tag.php index 2563172e2..48e1e65e3 100644 --- a/models/Tag.php +++ b/models/Tag.php @@ -1,9 +1,7 @@ hasMany('Photo', 'Phototag.photo_id'); - } - public function setTableDefinition() { - $this->hasColumn('tag', 'string', 100); + public static function initMetadata($class) { + $class->setColumn('tag', 'string', 100); + $class->hasMany('Photo', array('local' => 'tag_id', 'foreign' => 'photo_id', 'refClass' => 'Phototag')); } } diff --git a/models/Task.php b/models/Task.php index 9f5c3de90..e4359d94f 100644 --- a/models/Task.php +++ b/models/Task.php @@ -1,11 +1,9 @@ hasMany('Resource as ResourceAlias', 'Assignment.resource_id'); - $this->hasMany('Task as Subtask', 'Subtask.parent_id'); - } - public function setTableDefinition() { - $this->hasColumn('name', 'string',100); - $this->hasColumn('parent_id', 'integer'); + public static function initMetadata($class) { + $class->setColumn('name', 'string',100); + $class->setColumn('parent_id', 'integer'); + $class->hasMany('Resource as ResourceAlias', array('local' => 'task_id', 'foreign' => 'resource_id', 'refClass' => 'Assignment')); + $class->hasMany('Task as Subtask', array('local' => 'id', 'foreign' => 'parent_id')); } } diff --git a/models/TestMovie.php b/models/TestMovie.php index 482c6c542..bf7c8b252 100644 --- a/models/TestMovie.php +++ b/models/TestMovie.php @@ -2,26 +2,24 @@ class TestMovie extends Doctrine_Record { - public function setUp() + public static function initMetadata($class) { - $this->hasOne('TestUser as User', + $class->setColumn('user_id', 'integer', null); + $class->setColumn('name', 'string', 30); + + $class->hasOne('TestUser as User', array('local' => 'user_id', 'foreign' => 'id')); - $this->hasMany('TestUser as MovieBookmarks', + $class->hasMany('TestUser as MovieBookmarks', array('local' => 'movie_id', 'foreign' => 'user_id', 'refClass' => 'TestMovieUserBookmark')); - $this->hasMany('TestUser as MovieVotes', + $class->hasMany('TestUser as MovieVotes', array('local' => 'movie_id', 'foreign' => 'user_id', 'refClass' => 'TestMovieUserVote')); } - public function setTableDefinition() - { - $this->hasColumn('user_id', 'integer', null); - $this->hasColumn('name', 'string', 30); - } } diff --git a/models/TestMovieUserBookmark.php b/models/TestMovieUserBookmark.php index 3d84a036b..e03577da9 100644 --- a/models/TestMovieUserBookmark.php +++ b/models/TestMovieUserBookmark.php @@ -1,10 +1,10 @@ hasColumn('user_id', 'integer', null, array('primary' => true)); - $this->hasColumn('movie_id', 'integer', null, array('primary' => true)); + $class->setColumn('user_id', 'integer', null, array('primary' => true)); + $class->setColumn('movie_id', 'integer', null, array('primary' => true)); } } diff --git a/models/TestMovieUserVote.php b/models/TestMovieUserVote.php index 244f1f54a..bf36bba7b 100644 --- a/models/TestMovieUserVote.php +++ b/models/TestMovieUserVote.php @@ -1,9 +1,9 @@ hasColumn('vote', 'string', 30); - $this->hasColumn('user_id', 'integer', null, array('primary' => true)); - $this->hasColumn('movie_id', 'integer', null, array('primary' => true)); + public static function initMetadata($class) { + $class->setColumn('vote', 'string', 30); + $class->setColumn('user_id', 'integer', null, array('primary' => true)); + $class->setColumn('movie_id', 'integer', null, array('primary' => true)); } } diff --git a/models/TestRecord.php b/models/TestRecord.php index 9e1e445e5..2c9221ea3 100644 --- a/models/TestRecord.php +++ b/models/TestRecord.php @@ -1,8 +1,8 @@ setTableName('test'); + $class->setTableName('test'); } } diff --git a/models/TestUser.php b/models/TestUser.php index f2e2e6cc6..8fcf32ac2 100644 --- a/models/TestUser.php +++ b/models/TestUser.php @@ -1,21 +1,19 @@ hasMany('TestMovie as UserBookmarks', + $class->setColumn('name', 'string', 30); + $class->hasMany('TestMovie as UserBookmarks', array('local' => 'user_id', 'foreign' => 'movie_id', 'refClass' => 'TestMovieUserBookmark')); - $this->hasMany('TestMovie as UserVotes', + $class->hasMany('TestMovie as UserVotes', array('local' => 'user_id', 'foreign' => 'movie_id', 'refClass' => 'TestMovieUserVote')); } - public function setTableDefinition() - { - $this->hasColumn('name', 'string', 30); - } + } diff --git a/models/TreeLeaf.php b/models/TreeLeaf.php index 7a4a07de5..404062e85 100644 --- a/models/TreeLeaf.php +++ b/models/TreeLeaf.php @@ -1,15 +1,11 @@ hasColumn('name', 'string'); - $this->hasColumn('parent_id', 'integer'); + $class->setColumn('name', 'string'); + $class->setColumn('parent_id', 'integer'); + $class->hasOne('TreeLeaf as Parent', array('local' => 'parent_id', 'foreign' => 'id')); + $class->hasMany('TreeLeaf as Children', array('local' => 'id', 'foreign' => 'parent_id')); } - - public function setUp() - { - $this->hasOne('TreeLeaf as Parent', array('local' => 'parent_id', 'foreign' => 'id')); - $this->hasMany('TreeLeaf as Children', array('local' => 'id', 'foreign' => 'parent_id')); - } -} \ No newline at end of file +} diff --git a/models/User.php b/models/User.php index 263706ba8..5627a9f69 100644 --- a/models/User.php +++ b/models/User.php @@ -2,38 +2,28 @@ require_once('Entity.php'); -// UserTable doesn't extend Doctrine_Table -> Doctrine_Connection -// won't initialize grouptable when Doctrine_Connection->getTable('User') is called -class UserTable extends Doctrine_Table { } class User extends Entity { - public function setUp() + public static function initMetadata($class) { - parent::setUp(); - $this->hasMany('Address', array( + $class->hasMany('Address', array( 'local' => 'user_id', 'foreign' => 'address_id', 'refClass' => 'EntityAddress', )); - $this->hasMany('Address as Addresses', array( + $class->hasMany('Address as Addresses', array( 'local' => 'user_id', 'foreign' => 'address_id', 'refClass' => 'EntityAddress', )); - $this->hasMany('Album', array('local' => 'id', 'foreign' => 'user_id')); - $this->hasMany('Book', array('local' => 'id', 'foreign' => 'user_id')); - $this->hasMany('Group', array( + $class->hasMany('Album', array('local' => 'id', 'foreign' => 'user_id')); + $class->hasMany('Book', array('local' => 'id', 'foreign' => 'user_id')); + $class->hasMany('Group', array( 'local' => 'user_id', 'foreign' => 'group_id', - 'refClass' => 'Groupuser', - 'refRelationName' => 'UserGroupuser', - 'refReverseRelationName' => 'GroupGroupuser' - )); - /*$this->hasMany('Groupuser as Group', array( - 'local' => 'id', 'foreign' => 'user_id' - ));*/ - + 'refClass' => 'Groupuser' + )); } /** Custom validation */ diff --git a/models/ValidatorTest.php b/models/ValidatorTest.php index 052d6bc51..d825a7711 100644 --- a/models/ValidatorTest.php +++ b/models/ValidatorTest.php @@ -1,15 +1,15 @@ hasColumn('mymixed', 'string', 100); - $this->hasColumn('mystring', 'string', 100, array('notnull', 'unique')); - $this->hasColumn('myarray', 'array', 1000); - $this->hasColumn('myobject', 'object', 1000); - $this->hasColumn('myinteger', 'integer', 11); - $this->hasColumn('myrange', 'integer', 11, array('range' => array(4,123))); - $this->hasColumn('myregexp', 'string', 5, array('regexp' => '/^[0-9]+$/')); + public static function initMetadata($class) { + $class->setColumn('mymixed', 'string', 100); + $class->setColumn('mystring', 'string', 100, array('notnull', 'unique')); + $class->setColumn('myarray', 'array', 1000); + $class->setColumn('myobject', 'object', 1000); + $class->setColumn('myinteger', 'integer', 11); + $class->setColumn('myrange', 'integer', 11, array('range' => array(4,123))); + $class->setColumn('myregexp', 'string', 5, array('regexp' => '/^[0-9]+$/')); - $this->hasColumn('myemail', 'string', 100, array('email')); - $this->hasColumn('myemail2', 'string', 100, array('email', 'notblank')); + $class->setColumn('myemail', 'string', 100, array('email')); + $class->setColumn('myemail2', 'string', 100, array('email', 'notblank')); } } diff --git a/models/ValidatorTest_AddressModel.php b/models/ValidatorTest_AddressModel.php index bbaab3147..3949fd895 100644 --- a/models/ValidatorTest_AddressModel.php +++ b/models/ValidatorTest_AddressModel.php @@ -1,18 +1,14 @@ hasColumn("id", "integer", 11, array('autoincrement' => true, + public static function initMetadata($class) { + $class->setColumn("id", "integer", 11, array('autoincrement' => true, 'primary' => true )); - $this->hasColumn('address1', 'string', 255, array('notnull' => true, 'notblank')); - $this->hasColumn('address2', 'string', 255, array('notnull' => true)); - $this->hasColumn('city', 'string', 255, array('notnull' => true, 'notblank')); - $this->hasColumn('state', 'string', 10, array('notnull' => true, 'notblank', 'usstate')); - $this->hasColumn('zip', 'string', 15, array('notnull' => true, 'notblank', 'regexp' => '/^[0-9-]*$/')); - } - - public function setUp() { - $this->hasMany('ValidatorTest_ClientModel', array('local' => 'address_id', 'foreign' => 'client_id', 'refClass' => 'ValidatorTest_ClientToAddressModel')); + $class->setColumn('address1', 'string', 255, array('notnull' => true, 'notblank')); + $class->setColumn('address2', 'string', 255, array('notnull' => true)); + $class->setColumn('city', 'string', 255, array('notnull' => true, 'notblank')); + $class->setColumn('state', 'string', 10, array('notnull' => true, 'notblank', 'usstate')); + $class->setColumn('zip', 'string', 15, array('notnull' => true, 'notblank', 'regexp' => '/^[0-9-]*$/')); + $class->hasMany('ValidatorTest_ClientModel', array('local' => 'address_id', 'foreign' => 'client_id', 'refClass' => 'ValidatorTest_ClientToAddressModel')); } } diff --git a/models/ValidatorTest_ClientModel.php b/models/ValidatorTest_ClientModel.php index e0e12d716..f5d06c526 100644 --- a/models/ValidatorTest_ClientModel.php +++ b/models/ValidatorTest_ClientModel.php @@ -1,15 +1,11 @@ hasColumn('id', 'integer', 4, array('notnull' => true, + public static function initMetadata($class) { + $class->setColumn('id', 'integer', 4, array('notnull' => true, 'primary' => true, 'autoincrement' => true, 'unsigned' => true)); - $this->hasColumn('short_name', 'string', 32, array('notnull' => true, 'notblank', 'unique' => true)); - } - - public function setUp() { - $this->hasMany("ValidatorTest_AddressModel", array('local' => 'client_id', 'foreign' => 'address_id', 'refClass' => 'ValidatorTest_ClientToAddressModel')); + $class->setColumn('short_name', 'string', 32, array('notnull' => true, 'notblank', 'unique' => true)); + $class->hasMany("ValidatorTest_AddressModel", array('local' => 'client_id', 'foreign' => 'address_id', 'refClass' => 'ValidatorTest_ClientToAddressModel')); } } diff --git a/models/ValidatorTest_ClientToAddressModel.php b/models/ValidatorTest_ClientToAddressModel.php index 50375d4a9..00a973d21 100644 --- a/models/ValidatorTest_ClientToAddressModel.php +++ b/models/ValidatorTest_ClientToAddressModel.php @@ -1,15 +1,8 @@ hasColumn("client_id", "integer", 11, array('primary' => true)); - $this->hasColumn("address_id", "integer", 11, array('primary' => true)); - } - - public function construct(){ - } - - public function setUp() { + public static function initMetadata($class) { + $class->setColumn("client_id", "integer", 11, array('primary' => true)); + $class->setColumn("address_id", "integer", 11, array('primary' => true)); } } diff --git a/models/ValidatorTest_DateModel.php b/models/ValidatorTest_DateModel.php index 0aaf1d5eb..ee988d383 100644 --- a/models/ValidatorTest_DateModel.php +++ b/models/ValidatorTest_DateModel.php @@ -1,7 +1,7 @@ hasColumn('birthday', 'date', null, array('past')); - $this->hasColumn('death', 'date', null, array('future')); + public static function initMetadata($class) { + $class->setColumn('birthday', 'date', null, array('past')); + $class->setColumn('death', 'date', null, array('future')); } } diff --git a/models/ValidatorTest_FootballPlayer.php b/models/ValidatorTest_FootballPlayer.php index e5a1693d7..7c53edb3d 100644 --- a/models/ValidatorTest_FootballPlayer.php +++ b/models/ValidatorTest_FootballPlayer.php @@ -1,8 +1,8 @@ hasColumn('person_id', 'string', 255); - $this->hasColumn('team_name', 'string', 255); - $this->hasColumn('goals_count', 'integer', 4); + public static function initMetadata($class) { + $class->setColumn('person_id', 'string', 255); + $class->setColumn('team_name', 'string', 255); + $class->setColumn('goals_count', 'integer', 4); } } diff --git a/models/ValidatorTest_Person.php b/models/ValidatorTest_Person.php index 58ef41e19..54be2fa9b 100644 --- a/models/ValidatorTest_Person.php +++ b/models/ValidatorTest_Person.php @@ -1,11 +1,8 @@ hasColumn('identifier', 'integer', 4, array('notblank', 'unique')); - $this->hasColumn('is_football_player', 'boolean'); - } - - public function setUp() { - $this->hasOne('ValidatorTest_FootballPlayer', 'ValidatorTest_FootballPlayer.person_id'); + public static function initMetadata($class) { + $class->setColumn('identifier', 'integer', 4, array('notblank', 'unique')); + $class->setColumn('is_football_player', 'boolean'); + $class->hasOne('ValidatorTest_FootballPlayer', array('local' => 'id', 'foreign' => 'person_id')); } } diff --git a/models/VersioningTest.php b/models/VersioningTest.php index 7cb60d492..83d349c14 100644 --- a/models/VersioningTest.php +++ b/models/VersioningTest.php @@ -1,13 +1,10 @@ hasColumn('name', 'string'); - $this->hasColumn('version', 'integer'); - } - public function setUp() - { - $this->actAs('Versionable'); + $class->setColumn('name', 'string'); + $class->setColumn('version', 'integer'); + $class->actAs('Versionable'); } } diff --git a/models/ZeroValueTest.php b/models/ZeroValueTest.php index 5976148e7..1e80ca6b9 100644 --- a/models/ZeroValueTest.php +++ b/models/ZeroValueTest.php @@ -1,19 +1,16 @@ hasColumn('id', 'integer', 4, array('primary' => true, 'autoincrement' => true,)); - $this->hasColumn('username', 'string', 128, array('notnull' => true,)); - $this->hasColumn('algorithm', 'string', 128, array('default' => 'sha1', 'notnull' => true,)); - $this->hasColumn('salt', 'string', 128, array('notnull' => true,)); - $this->hasColumn('password', 'string', 128, array('notnull' => true,)); - $this->hasColumn('created_at', 'timestamp', null, array()); - $this->hasColumn('last_login', 'timestamp', null, array()); - $this->hasColumn('is_active', 'boolean', null, array('default' => true, 'notnull' => true,)); - $this->hasColumn('is_super_admin', 'boolean', null, array('default' => false, 'notnull' => true,)); + $class->setColumn('id', 'integer', 4, array('primary' => true, 'autoincrement' => true,)); + $class->setColumn('username', 'string', 128, array('notnull' => true,)); + $class->setColumn('algorithm', 'string', 128, array('default' => 'sha1', 'notnull' => true,)); + $class->setColumn('salt', 'string', 128, array('notnull' => true,)); + $class->setColumn('password', 'string', 128, array('notnull' => true,)); + $class->setColumn('created_at', 'timestamp', null, array()); + $class->setColumn('last_login', 'timestamp', null, array()); + $class->setColumn('is_active', 'boolean', null, array('default' => true, 'notnull' => true,)); + $class->setColumn('is_super_admin', 'boolean', null, array('default' => false, 'notnull' => true,)); } - - public function setUp() - { } } diff --git a/models/export/Cms_Category.php b/models/export/Cms_Category.php index 71db71650..ae539b07c 100644 --- a/models/export/Cms_Category.php +++ b/models/export/Cms_Category.php @@ -2,20 +2,17 @@ class Cms_Category extends Doctrine_Record { - public function setUp() + public static function initMetadata($class) { - $this->hasMany('Cms_CategoryLanguages as langs', array('local' => 'id', 'foreign' => 'category_id')); - } - - public function setTableDefinition() - { - $this->hasColumn('created', 'timestamp'); - $this->hasColumn('parent', 'integer', 11); - $this->hasColumn('position', 'integer', 3); - $this->hasColumn('active', 'integer', 11); - $this->option('collate', 'utf8_unicode_ci'); - $this->option('charset', 'utf8'); - $this->option('type', 'INNODB'); - $this->index('index_parent', array('fields' => array('parent'))); + $class->setColumn('created', 'timestamp'); + $class->setColumn('parent', 'integer', 11); + $class->setColumn('position', 'integer', 3); + $class->setColumn('active', 'integer', 11); + $class->setTableOption('collate', 'utf8_unicode_ci'); + $class->setTableOption('charset', 'utf8'); + $class->setTableOption('type', 'INNODB'); + $class->addIndex('index_parent', array('fields' => array('parent'))); + + $class->hasMany('Cms_CategoryLanguages as langs', array('local' => 'id', 'foreign' => 'category_id')); } } diff --git a/models/export/Cms_CategoryLanguages.php b/models/export/Cms_CategoryLanguages.php index 5a0f0bb6f..189ede9ae 100644 --- a/models/export/Cms_CategoryLanguages.php +++ b/models/export/Cms_CategoryLanguages.php @@ -1,21 +1,18 @@ setAttribute(Doctrine::ATTR_COLL_KEY, 'language_id'); - $this->hasOne('Cms_Category as category', array('local' => 'category_id', 'foreign' => 'id', 'onDelete' => 'CASCADE')); - } - - public function setTableDefinition() - { - $this->hasColumn('name', 'string',256); - $this->hasColumn('category_id', 'integer',11); - $this->hasColumn('language_id', 'integer',11); - $this->option('collate', 'utf8_unicode_ci'); - $this->option('charset', 'utf8'); - $this->option('type', 'INNODB'); - $this->index('index_category', array('fields' => array('category_id'))); - $this->index('index_language', array('fields' => array('language_id'))); + $class->setColumn('name', 'string',256); + $class->setColumn('category_id', 'integer',11); + $class->setColumn('language_id', 'integer',11); + $class->setTableOption('collate', 'utf8_unicode_ci'); + $class->setTableOption('charset', 'utf8'); + $class->setTableOption('type', 'INNODB'); + $class->addIndex('index_category', array('fields' => array('category_id'))); + $class->addIndex('index_language', array('fields' => array('language_id'))); + + $class->setAttribute(Doctrine::ATTR_COLL_KEY, 'language_id'); + $class->hasOne('Cms_Category as category', array('local' => 'category_id', 'foreign' => 'id', 'onDelete' => 'CASCADE')); } } diff --git a/models/gnatEmail.php b/models/gnatEmail.php index 209ef6fd3..0998b214f 100644 --- a/models/gnatEmail.php +++ b/models/gnatEmail.php @@ -1,9 +1,9 @@ hasColumn('address', 'string', 150); + $class->setColumn('address', 'string', 150); } diff --git a/models/gnatUser.php b/models/gnatUser.php index e6a66915b..a5a3bb2c8 100644 --- a/models/gnatUser.php +++ b/models/gnatUser.php @@ -3,17 +3,11 @@ class gnatUserTable { } class gnatUser extends Doctrine_Record { - public function setTableDefinition() + public static function initMetadata($class) { - $this->hasColumn('name', 'string', 150); - $this->hasColumn('foreign_id', 'integer', 10, array ('unique' => true,)); - } - - public function setUp() - { - parent::setUp(); - $this->hasOne('gnatEmail as Email', array('local'=> 'foreign_id', 'foreign'=>'id', 'onDelete'=>'CASCADE')); - } - + $class->setColumn('name', 'string', 150); + $class->setColumn('foreign_id', 'integer', 10, array ('unique' => true)); + $class->hasOne('gnatEmail as Email', array('local'=> 'foreign_id', 'foreign'=>'id', 'onDelete'=>'CASCADE')); + } } diff --git a/models/mmrGroupUser_B.php b/models/mmrGroupUser_B.php index 8d246383b..808e9b823 100644 --- a/models/mmrGroupUser_B.php +++ b/models/mmrGroupUser_B.php @@ -1,9 +1,9 @@ hasColumn('user_id', 'string', 30, array('primary' => true)); - $this->hasColumn('group_id', 'string', 30, array('primary' => true)); + $class->setColumn('user_id', 'string', 30, array('primary' => true)); + $class->setColumn('group_id', 'string', 30, array('primary' => true)); } } diff --git a/models/mmrGroupUser_C.php b/models/mmrGroupUser_C.php index 656e44df1..00756ff8d 100644 --- a/models/mmrGroupUser_C.php +++ b/models/mmrGroupUser_C.php @@ -2,9 +2,9 @@ class mmrGroupUser_C extends Doctrine_Record { - public function setTableDefinition() + public static function initMetadata($class) { - $this->hasColumn('user_id', 'string', 30, array('primary' => true)); - $this->hasColumn('group_id', 'string', 30, array('primary' => true)); + $class->setColumn('user_id', 'string', 30, array('primary' => true)); + $class->setColumn('group_id', 'string', 30, array('primary' => true)); } } diff --git a/models/mmrGroup_C.php b/models/mmrGroup_C.php index 6b8f865ff..e62650e4d 100644 --- a/models/mmrGroup_C.php +++ b/models/mmrGroup_C.php @@ -1,15 +1,12 @@ hasMany('mmrUser_C', array('local' => 'group_id', + $class->setColumn('g_id as id', 'string', 30, array('primary' => true)); + $class->setColumn('name', 'string', 30); + $class->hasMany('mmrUser_C', array('local' => 'group_id', 'foreign' => 'user_id', 'refClass' => 'mmrGroupUser_C')); } - public function setTableDefinition() - { - $this->hasColumn('g_id as id', 'string', 30, array('primary' => true)); - $this->hasColumn('name', 'string', 30); - } } diff --git a/tests/AuditLogTestCase.php b/tests/AuditLogTestCase.php index 6eefceee1..930ed1301 100644 --- a/tests/AuditLogTestCase.php +++ b/tests/AuditLogTestCase.php @@ -40,7 +40,7 @@ class Doctrine_AuditLog_TestCase extends Doctrine_UnitTestCase { $this->profiler = new Doctrine_Connection_Profiler(); $this->conn->addListener($this->profiler); - $this->tables = array('VersioningTest', 'VersioningTestVersion'); + $this->tables = array('VersioningTest'); parent::prepareTables(); } diff --git a/tests/Collection/SnapshotTestCase.php b/tests/Collection/SnapshotTestCase.php index 3daa954fc..967af92c3 100644 --- a/tests/Collection/SnapshotTestCase.php +++ b/tests/Collection/SnapshotTestCase.php @@ -40,7 +40,7 @@ class Doctrine_Collection_Snapshot_TestCase extends Doctrine_UnitTestCase { public function prepareTables() { - $this->tables = array('Entity', 'User', 'Group', 'GroupUser', 'Account', 'Album', 'Phonenumber', 'Email', 'Book'); + $this->tables = array('Entity', 'User', 'Group', 'Groupuser', 'Account', 'Album', 'Phonenumber', 'Email', 'Book'); parent::prepareTables(); } diff --git a/tests/ColumnAggregationInheritanceTestCase.php b/tests/ColumnAggregationInheritanceTestCase.php index 7c0134601..f4e889380 100644 --- a/tests/ColumnAggregationInheritanceTestCase.php +++ b/tests/ColumnAggregationInheritanceTestCase.php @@ -35,33 +35,25 @@ class Doctrine_ColumnAggregationInheritance_TestCase extends Doctrine_UnitTestCa { protected $otherEntity = null; + /*public function prepareTables() + { + + }*/ + public function prepareData() { - parent::prepareData(); //we create a test entity that is not a user and not a group - $entity = new Entity(); + $entity = new Group(); $entity->name='Other Entity'; - $entity->type = 2; $entity->save(); - $this->otherEntity = $entity; - } - - public function testQueriedClassReturnedIfNoSubclassMatch() - { - $q = new Doctrine_Query(); - $entityOther = $q->from('Entity')->where('id = ?')->execute(array($this->otherEntity->id))->getFirst(); - $this->assertTrue($entityOther instanceOf Entity); } public function testSubclassReturnedIfInheritanceMatches() { $q = new Doctrine_Query(); - $group = $q->from('Entity')->where('id=?')->execute(array(1))->getFirst(); + //echo $q->from('Entity e')->getSql(); + $group = $q->from('Entity e')->execute()->getFirst(); $this->assertTrue($group instanceOf Group); - - $q = new Doctrine_Query(); - $user = $q->from('Entity')->where('id=?')->execute(array(5))->getFirst(); - $this->assertTrue($user instanceOf User); } public function testStringColumnInheritance() { diff --git a/tests/ConnectionTestCase.php b/tests/ConnectionTestCase.php index 2efccbd6c..46b47a778 100644 --- a/tests/ConnectionTestCase.php +++ b/tests/ConnectionTestCase.php @@ -158,10 +158,10 @@ class Doctrine_Connection_TestCase extends Doctrine_UnitTestCase public function testGetTable() { - $table = $this->connection->getTable('Group'); - $this->assertTrue($table instanceof Doctrine_Table); + $table = $this->connection->getClassMetadata('Group'); + $this->assertTrue($table instanceof Doctrine_ClassMetadata); try { - $table = $this->connection->getTable('Unknown'); + $table = $this->connection->getClassMetadata('Unknown'); $f = false; } catch(Doctrine_Exception $e) { $f = true; @@ -196,11 +196,6 @@ class Doctrine_Connection_TestCase extends Doctrine_UnitTestCase $this->assertEqual(Doctrine_Lib::getConnectionStateAsString($this->connection->transaction->getState()), 'open'); } - public function testGetTables() - { - $this->assertTrue(is_array($this->connection->getTables())); - } - public function testRollback() { $this->connection->beginTransaction(); diff --git a/tests/DoctrineTest/Doctrine_UnitTestCase.php b/tests/DoctrineTest/Doctrine_UnitTestCase.php index 31c514199..9c52a44e6 100644 --- a/tests/DoctrineTest/Doctrine_UnitTestCase.php +++ b/tests/DoctrineTest/Doctrine_UnitTestCase.php @@ -65,32 +65,33 @@ class Doctrine_UnitTestCase extends UnitTestCase { $this->_name = get_class($this); - $this->manager = Doctrine_Manager::getInstance(); + $this->manager = Doctrine_Manager::getInstance(); $this->manager->setAttribute(Doctrine::ATTR_EXPORT, Doctrine::EXPORT_ALL); $this->tables = array_merge($this->tables, - array('entity', - 'entityReference', - 'email', - 'phonenumber', - 'groupuser', - 'album', - 'song', - 'element', - 'error', - 'description', - 'address', - 'account', - 'task', - 'resource', - 'assignment', - 'resourceType', - 'resourceReference') + array('Entity', + 'EntityReference', + 'Email', + 'Phonenumber', + 'Groupuser', + 'Album', + 'Book', + 'Song', + 'Element', + 'Error', + 'Description', + 'Address', + 'Account', + 'Task', + 'Resource', + 'Assignment', + 'ResourceType', + 'ResourceReference') ); $class = get_class($this); - $e = explode('_', $class); + $e = explode('_', $class); if ( ! $this->driverName) { @@ -134,7 +135,7 @@ class Doctrine_UnitTestCase extends UnitTestCase $this->manager->setAttribute(Doctrine::ATTR_LISTENER, $this->listener); - } catch(Doctrine_Manager_Exception $e) { + } catch (Doctrine_Manager_Exception $e) { if($this->driverName == 'main') { $this->dbh = new PDO('sqlite::memory:'); $this->dbh->sqliteCreateFunction('trim', 'trim', 1); @@ -144,7 +145,7 @@ class Doctrine_UnitTestCase extends UnitTestCase $this->conn = $this->connection = $this->manager->openConnection($this->dbh, $this->driverName); - if($this->driverName !== 'main') { + if ($this->driverName !== 'main') { $exc = 'Doctrine_Connection_' . ucwords($this->driverName) . '_Exception'; $this->exc = new $exc(); @@ -155,8 +156,8 @@ class Doctrine_UnitTestCase extends UnitTestCase $this->listener = new Doctrine_EventListener(); $this->manager->setAttribute(Doctrine::ATTR_LISTENER, $this->listener); } + if ($this->driverName !== 'main') { - if (isset($module)) { switch($module) { case 'Export': @@ -174,29 +175,31 @@ class Doctrine_UnitTestCase extends UnitTestCase } } } + $this->unitOfWork = $this->connection->unitOfWork; $this->connection->setListener(new Doctrine_EventListener()); $this->query = new Doctrine_Query($this->connection); - + if ($this->driverName === 'main') { $this->prepareTables(); $this->prepareData(); } } + public function prepareTables() { - foreach($this->tables as $name) { - $name = ucwords($name); - $table = $this->connection->getTable($name); + foreach ($this->tables as $name) { + $table = $this->connection->getMetadata($name); $query = 'DROP TABLE ' . $table->getTableName(); try { $this->conn->exec($query); - } catch(Doctrine_Connection_Exception $e) { - - } + } catch (Doctrine_Connection_Exception $e) {} } + //echo "exporting : " . var_dump($this->tables); + //echo "

"; $this->conn->export->exportClasses($this->tables); $this->objTable = $this->connection->getMapper('User'); } + public function prepareData() { $groups = new Doctrine_Collection('Group'); @@ -255,10 +258,12 @@ class Doctrine_UnitTestCase extends UnitTestCase $this->users = $users; $this->users->save(); } + public function getConnection() { return $this->connection; } + public function assertDeclarationType($type, $type2) { $dec = $this->getDeclaration($type); @@ -269,10 +274,12 @@ class Doctrine_UnitTestCase extends UnitTestCase $this->assertEqual($dec['type'], $type2); } + public function getDeclaration($type) { return $this->dataDict->getPortableDeclaration(array('type' => $type, 'name' => 'colname', 'length' => 1, 'fixed' => true)); } + public function clearCache() { foreach($this->tables as $name) { @@ -280,11 +287,13 @@ class Doctrine_UnitTestCase extends UnitTestCase $table->getCache()->deleteAll(); } } + public function setUp() { if ( ! $this->init) { $this->init(); } + if (isset($this->objTable)) { $this->objTable->clear(); } diff --git a/tests/Hydrate/FetchModeTestCase.php b/tests/Hydrate/FetchModeTestCase.php index ae5671179..d0b11559b 100644 --- a/tests/Hydrate/FetchModeTestCase.php +++ b/tests/Hydrate/FetchModeTestCase.php @@ -45,6 +45,7 @@ class Doctrine_Hydrate_FetchMode_TestCase extends Doctrine_UnitTestCase $this->assertEqual(count($users), 1); } + public function testFetchArraySupportsOneToManyRelations2() { $q = new Doctrine_Query(); @@ -57,6 +58,7 @@ class Doctrine_Hydrate_FetchMode_TestCase extends Doctrine_UnitTestCase $this->assertEqual(count($users), 8); } + public function testFetchArraySupportsOneToManyRelations3() { $q = new Doctrine_Query(); @@ -70,6 +72,7 @@ class Doctrine_Hydrate_FetchMode_TestCase extends Doctrine_UnitTestCase $this->assertEqual(count($users), 1); $this->assertEqual(count($users[0]['Phonenumber']), 3); } + public function testFetchArraySupportsOneToOneRelations() { $q = new Doctrine_Query(); @@ -81,6 +84,7 @@ class Doctrine_Hydrate_FetchMode_TestCase extends Doctrine_UnitTestCase $this->assertEqual(count($users), 8); $this->assertEqual($users[0]['Email']['address'], 'zYne@example.com'); } + public function testFetchArraySupportsOneToOneRelations2() { $q = new Doctrine_Query(); diff --git a/tests/HydrateTestCase.php b/tests/HydrateTestCase.php index 04e66ab73..fbd539fc2 100644 --- a/tests/HydrateTestCase.php +++ b/tests/HydrateTestCase.php @@ -60,7 +60,7 @@ class Doctrine_Hydrate_TestCase extends Doctrine_UnitTestCase public function testHydrateHooks() { $user = new User(); - $user->getTable()->addRecordListener(new HydrationListener); + $user->getMapper()->addRecordListener(new HydrationListener); $user->name = 'zYne'; $user->save(); @@ -71,6 +71,8 @@ class Doctrine_Hydrate_TestCase extends Doctrine_UnitTestCase $this->assertEqual($user->name, 'ZYNE'); $this->assertEqual($user->password, 'DEFAULT PASS'); + + } } class HydrationListener extends Doctrine_Record_Listener diff --git a/tests/Import/MssqlTestCase.php b/tests/Import/MssqlTestCase.php index 5a72b31a4..e6cb8a3c2 100644 --- a/tests/Import/MssqlTestCase.php +++ b/tests/Import/MssqlTestCase.php @@ -49,7 +49,7 @@ class Doctrine_Import_Mssql_TestCase extends Doctrine_UnitTestCase { $this->import->listTables(); - $this->assertEqual($this->adapter->pop(), "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name"); + $this->assertEqual($this->adapter->pop(), "SELECT name FROM sysobjects WHERE type = 'U' AND name <> 'dtproperties' ORDER BY name"); } public function testListTriggersExecutesSql() { diff --git a/tests/Inheritance/JoinedTestCase.php b/tests/Inheritance/JoinedTestCase.php index 56bf8854b..61123a008 100644 --- a/tests/Inheritance/JoinedTestCase.php +++ b/tests/Inheritance/JoinedTestCase.php @@ -23,20 +23,20 @@ class Doctrine_Inheritance_Joined_TestCase extends Doctrine_UnitTestCase public function testMetadataSetup() { - $suManagerTable = $this->conn->getTable('CTI_SuperManager'); - $userTable = $this->conn->getTable('CTI_User'); - $customerTable = $this->conn->getTable('CTI_Customer'); - $managerTable = $this->conn->getTable('CTI_Manager'); + $suManagerTable = $this->conn->getMetadata('CTI_SuperManager'); + $userTable = $this->conn->getMetadata('CTI_User'); + $customerTable = $this->conn->getMetadata('CTI_Customer'); + $managerTable = $this->conn->getMetadata('CTI_Manager'); $this->assertTrue($suManagerTable !== $userTable); $this->assertTrue($suManagerTable !== $customerTable); $this->assertTrue($userTable !== $customerTable); $this->assertTrue($managerTable !== $suManagerTable); // expected column counts - $this->assertEqual(2, count($suManagerTable->getColumns())); + $this->assertEqual(6, count($suManagerTable->getColumns())); $this->assertEqual(4, count($userTable->getColumns())); - $this->assertEqual(2, count($managerTable->getColumns())); - $this->assertEqual(2, count($customerTable->getColumns())); + $this->assertEqual(5, count($managerTable->getColumns())); + $this->assertEqual(5, count($customerTable->getColumns())); // expected table names $this->assertEqual('cti_user', $userTable->getTableName()); @@ -45,20 +45,15 @@ class Doctrine_Inheritance_Joined_TestCase extends Doctrine_UnitTestCase $this->assertEqual('cti_supermanager', $suManagerTable->getTableName()); // expected joined parents option - $this->assertEqual(array(), $userTable->getOption('joinedParents')); - $this->assertEqual(array('CTI_User'), $managerTable->getOption('joinedParents')); - $this->assertEqual(array('CTI_User'), $customerTable->getOption('joinedParents')); - $this->assertEqual(array('CTI_Manager', 'CTI_User'), $suManagerTable->getOption('joinedParents')); + $this->assertEqual(array(), $userTable->getOption('parents')); + $this->assertEqual(array('CTI_User'), $managerTable->getOption('parents')); + $this->assertEqual(array('CTI_User'), $customerTable->getOption('parents')); + $this->assertEqual(array('CTI_Manager', 'CTI_User'), $suManagerTable->getOption('parents')); // check inheritance map - $this->assertEqual(array( - 'CTI_User' => array('type' => 1), - 'CTI_Manager' => array('type' => 2), - 'CTI_Customer' => array('type' => 3), - 'CTI_SuperManager' => array('type' => 4)), $userTable->getOption('inheritanceMap')); - + $this->assertEqual(array(1 => 'CTI_User', 2 => 'CTI_Manager', + 3 => 'CTI_Customer', 4 => 'CTI_SuperManager'), $userTable->getInheritanceOption('discriminatorMap')); - //$this->assertEqual(array('CTI_User', 'CTI_Manager', '')) } protected function _createManager() @@ -97,14 +92,14 @@ class Doctrine_Inheritance_Joined_TestCase extends Doctrine_UnitTestCase $this->assertEqual(1, $manager->id); $this->assertEqual(80000, $manager->salary); $this->assertEqual('John Smith', $manager->name); - $this->assertEqual(2, $manager->type); + $this->assertTrue($manager instanceof CTI_Manager); $superManager = $this->_createSuperManager(); $this->assertEqual(2, $superManager->id); $this->assertEqual(1000000, $superManager->salary); $this->assertEqual('Bill Gates', $superManager->name); $this->assertEqual('BillyBoy', $superManager->gosutitle); - $this->assertEqual(4, $superManager->type); + $this->assertTrue($superManager instanceof CTI_SuperManager); } public function testUpdateUpdatesDataAcrossJoinedTablesTransparently() @@ -121,7 +116,7 @@ class Doctrine_Inheritance_Joined_TestCase extends Doctrine_UnitTestCase $this->assertEqual(1, $manager->id); $this->assertEqual(90000, $manager->salary); $this->assertEqual('John Locke', $manager->name); - $this->assertEqual(2, $manager->type); + $this->assertTrue($manager instanceof CTI_Manager); $superManager = $this->_createSuperManager(); @@ -138,7 +133,7 @@ class Doctrine_Inheritance_Joined_TestCase extends Doctrine_UnitTestCase $this->assertEqual(0, $superManager->salary); $this->assertEqual('Bill Clinton', $superManager->name); $this->assertEqual('Billy the Kid', $superManager->gosutitle); - $this->assertEqual(4, $superManager->type); + $this->assertTrue($superManager instanceof CTI_SuperManager); } public function testDqlQueryJoinsTransparentlyAcrossParents() @@ -154,7 +149,6 @@ class Doctrine_Inheritance_Joined_TestCase extends Doctrine_UnitTestCase $this->assertEqual(1, $manager->id); $this->assertEqual(80000, $manager->salary); $this->assertEqual('John Smith', $manager->name); - $this->assertEqual(2, $manager->type); } public function testQueryingBaseClassOuterJoinsSubClassesAndReturnsSubclassInstances() @@ -172,60 +166,54 @@ class Doctrine_Inheritance_Joined_TestCase extends Doctrine_UnitTestCase $this->assertEqual(1, $user->id); $this->assertEqual(80000, $user->salary); $this->assertEqual('John Smith', $user->name); - $this->assertEqual(2, $user->type); } } class CTI_User extends Doctrine_Record { - public function setTableDefinition() + public static function initMetadata($class) { - $this->setInheritanceType(Doctrine::INHERITANCETYPE_JOINED, - array('CTI_User' => array('type' => 1), - 'CTI_Manager' => array('type' => 2), - 'CTI_Customer' => array('type' => 3), - 'CTI_SuperManager' => array('type' => 4)) - );/* $class->setInheritanceType(Doctrine::INHERITANCETYPE_JOINED, array( - 'discriminatorColumn' => 'type', - 'map' => array(1 => 'CTI_User', 2 => 'CTI_Manager', 3 => 'CTI_Customer', - 4 => 'CTI_SuperManager') + 'discriminatorColumn' => 'dtype', + 'discriminatorMap' => array(1 => 'CTI_User', 2 => 'CTI_Manager', + 3 => 'CTI_Customer', 4 => 'CTI_SuperManager') )); - $class->setDiscriminatorValue(1); - $class->setInheritanceOption('fetchType', 'explicit'); - */ - $this->setTableName('cti_user'); - $this->hasColumn('cti_id as id', 'integer', 4, array('primary' => true, 'autoincrement' => true)); - $this->hasColumn('cti_foo as foo', 'integer', 4); - $this->hasColumn('cti_name as name', 'string', 50); - $this->hasColumn('type', 'integer', 4); - } + $class->setSubclasses(array('CTI_Manager', 'CTI_Customer', 'CTI_SuperManager')); + $class->setTableName('cti_user'); + $class->setColumn('cti_id as id', 'integer', 4, array('primary' => true, 'autoincrement' => true)); + $class->setColumn('cti_foo as foo', 'integer', 4); + $class->setColumn('cti_name as name', 'string', 50); + $class->setColumn('dtype', 'integer', 2); + } } class CTI_Manager extends CTI_User { - public function setTableDefinition() + protected $name; + + public static function initMetadata($class) { - $this->setTableName('cti_manager'); - $this->hasColumn('ctim_salary as salary', 'varchar', 50, array()); + $class->setTableName('cti_manager'); + $class->setSubclasses(array('CTI_SuperManager')); + $class->setColumn('ctim_salary as salary', 'varchar', 50, array()); } } class CTI_Customer extends CTI_User { - public function setTableDefinition() + public static function initMetadata($class) { - $this->setTableName('cti_customer'); - $this->hasColumn('ctic_bonuspoints as bonuspoints', 'varchar', 50, array()); + $class->setTableName('cti_customer'); + $class->setColumn('ctic_bonuspoints as bonuspoints', 'varchar', 50, array()); } } class CTI_SuperManager extends CTI_Manager { - public function setTableDefinition() + public static function initMetadata($class) { - $this->setTableName('cti_supermanager'); - $this->hasColumn('ctism_gosutitle as gosutitle', 'varchar', 50, array()); + $class->setTableName('cti_supermanager'); + $class->setColumn('ctism_gosutitle as gosutitle', 'varchar', 50, array()); } } diff --git a/tests/Inheritance/SingleTableTestCase.php b/tests/Inheritance/SingleTableTestCase.php index c8461d7ac..e9aa6984d 100644 --- a/tests/Inheritance/SingleTableTestCase.php +++ b/tests/Inheritance/SingleTableTestCase.php @@ -17,28 +17,20 @@ class Doctrine_Inheritance_SingleTable_TestCase extends Doctrine_UnitTestCase public function testMetadataSetup() { - $userTable = $this->conn->getTable('STI_User'); - $superManagerTable = $this->conn->getTable('STI_SuperManager'); - $managerTable = $this->conn->getTable('STI_Manager'); - $customerTable = $this->conn->getTable('STI_Customer'); + $userTable = $this->conn->getMetadata('STI_User'); + $superManagerTable = $this->conn->getMetadata('STI_SuperManager'); + $managerTable = $this->conn->getMetadata('STI_Manager'); + $customerTable = $this->conn->getMetadata('STI_Customer'); - $this->assertTrue($superManagerTable === $userTable); - $this->assertTrue($customerTable === $managerTable); - $this->assertTrue($superManagerTable === $managerTable); - $this->assertTrue($userTable === $customerTable); - $this->assertEqual(7, count($userTable->getColumns())); - - $this->assertEqual(array(), $userTable->getOption('joinedParents')); - $this->assertEqual(array(), $superManagerTable->getOption('joinedParents')); - $this->assertEqual(array(), $managerTable->getOption('joinedParents')); - $this->assertEqual(array(), $customerTable->getOption('joinedParents')); + $this->assertEqual(4, count($userTable->getFields())); + $this->assertEqual('sti_entity', $userTable->getTableName()); + $this->assertEqual('sti_entity', $managerTable->getTableName()); // check inheritance map - $this->assertEqual(array( - 'STI_User' => array('type' => 1), - 'STI_Manager' => array('type' => 2), - 'STI_Customer' => array('type' => 3), - 'STI_SuperManager' => array('type' => 4)), $userTable->getOption('inheritanceMap')); + $this->assertEqual(array(1 => 'STI_User', + 2 => 'STI_Manager', + 3 => 'STI_Customer', + 4 => 'STI_SuperManager'), $userTable->getInheritanceOption('discriminatorMap')); //var_dump($superManagerTable->getComponentName()); } @@ -73,42 +65,46 @@ class Doctrine_Inheritance_SingleTable_TestCase extends Doctrine_UnitTestCase class STI_User extends Doctrine_Record { - public function setTableDefinition() + public static function initMetadata($class) { - $this->setInheritanceType(Doctrine::INHERITANCETYPE_SINGLE_TABLE, - array('STI_User' => array('type' => 1), - 'STI_Manager' => array('type' => 2), - 'STI_Customer' => array('type' => 3), - 'STI_SuperManager' => array('type' => 4)) + $class->setInheritanceType(Doctrine::INHERITANCETYPE_SINGLE_TABLE, array( + 'discriminatorColumn' => 'type', + 'discriminatorMap' => array( + 1 => 'STI_User', + 2 => 'STI_Manager', + 3 => 'STI_Customer', + 4 => 'STI_SuperManager')) ); - $this->setTableName('sti_entity'); - $this->hasColumn('sti_id as id', 'integer', 4, array('primary' => true, 'autoincrement' => true)); - $this->hasColumn('sti_foo as foo', 'integer', 4); - $this->hasColumn('sti_name as name', 'varchar', 50); - $this->hasColumn('type', 'integer', 4); + $class->setSubclasses(array('STI_Manager', 'STI_Customer', 'STI_SuperManager')); + $class->setTableName('sti_entity'); + $class->setColumn('sti_id as id', 'integer', 4, array('primary' => true, 'autoincrement' => true)); + $class->setColumn('sti_foo as foo', 'integer', 4); + $class->setColumn('sti_name as name', 'varchar', 50); + $class->setColumn('type', 'integer', 4); } } class STI_Manager extends STI_User { - public function setTableDefinition() + public static function initMetadata($class) { - $this->hasColumn('stim_salary as salary', 'varchar', 50, array()); + $class->setSubclasses(array('STI_SuperManager')); + $class->setColumn('stim_salary as salary', 'varchar', 50, array()); } } class STI_Customer extends STI_User { - public function setTableDefinition() + public static function initMetadata($class) { - $this->hasColumn('stic_bonuspoints as bonuspoints', 'varchar', 50, array()); + $class->setColumn('stic_bonuspoints as bonuspoints', 'varchar', 50, array()); } } class STI_SuperManager extends STI_Manager { - public function setTableDefinition() + public static function initMetadata($class) { - $this->hasColumn('stism_gosutitle as gosutitle', 'varchar', 50, array()); + $class->setColumn('stism_gosutitle as gosutitle', 'varchar', 50, array()); } } diff --git a/tests/Inheritance/TablePerClassTestCase.php b/tests/Inheritance/TablePerClassTestCase.php index 59c8d7705..3f0819021 100644 --- a/tests/Inheritance/TablePerClassTestCase.php +++ b/tests/Inheritance/TablePerClassTestCase.php @@ -25,14 +25,10 @@ class Doctrine_Inheritance_TablePerClass_TestCase extends Doctrine_UnitTestCase public function testMetadataTableSetup() { - $supMngrTable = $this->conn->getTable('CCTI_SuperManager'); - $usrTable = $this->conn->getTable('CCTI_User'); - $mngrTable = $this->conn->getTable('CCTI_Manager'); - $customerTable = $this->conn->getTable('CCTI_Customer'); - $this->assertTrue($supMngrTable !== $usrTable); - $this->assertTrue($supMngrTable !== $mngrTable); - $this->assertTrue($usrTable !== $mngrTable); - $this->assertTrue($customerTable !== $usrTable); + $supMngrTable = $this->conn->getClassMetadata('CCTI_SuperManager'); + $usrTable = $this->conn->getClassMetadata('CCTI_User'); + $mngrTable = $this->conn->getClassMetadata('CCTI_Manager'); + $customerTable = $this->conn->getClassMetadata('CCTI_Customer'); $this->assertEqual(3, count($usrTable->getColumns())); $this->assertEqual(4, count($mngrTable->getColumns())); @@ -72,39 +68,41 @@ class Doctrine_Inheritance_TablePerClass_TestCase extends Doctrine_UnitTestCase class CCTI_User extends Doctrine_Record { - public function setTableDefinition() + public static function initMetadata($class) { - $this->setInheritanceType(Doctrine::INHERITANCETYPE_TABLE_PER_CLASS); - $this->setTableName('ccti_user'); - $this->hasColumn('ccti_id as id', 'integer', 4, array ('primary' => true, 'autoincrement' => true)); - $this->hasColumn('ccti_foo as foo', 'integer', 4); - $this->hasColumn('ccti_name as name', 'varchar', 50, array ()); + $class->setInheritanceType(Doctrine::INHERITANCETYPE_TABLE_PER_CLASS); + $class->setTableName('ccti_user'); + $class->setSubclasses(array('CCTI_Manager', 'CCTI_Customer', 'CCTI_SuperManager')); + $class->setColumn('ccti_id as id', 'integer', 4, array ('primary' => true, 'autoincrement' => true)); + $class->setColumn('ccti_foo as foo', 'integer', 4); + $class->setColumn('ccti_name as name', 'varchar', 50, array ()); } } class CCTI_Manager extends CCTI_User { - public function setTableDefinition() + public static function initMetadata($class) { - $this->setTableName('ccti_manager'); - $this->hasColumn('ccti_salary as salary', 'varchar', 50, array()); + $class->setTableName('ccti_manager'); + $class->setSubclasses(array('CCTI_SuperManager')); + $class->setColumn('ccti_salary as salary', 'varchar', 50, array()); } } class CCTI_Customer extends CCTI_User { - public function setTableDefinition() + public static function initMetadata($class) { - $this->setTableName('ccti_customer'); - $this->hasColumn('ccti_bonuspoints as bonuspoints', 'varchar', 50, array()); + $class->setTableName('ccti_customer'); + $class->setColumn('ccti_bonuspoints as bonuspoints', 'varchar', 50, array()); } } class CCTI_SuperManager extends CCTI_Manager { - public function setTableDefinition() + public static function initMetadata($class) { - $this->setTableName('ccti_supermanager'); - $this->hasColumn('ccti_gosutitle as gosutitle', 'varchar', 50, array()); + $class->setTableName('ccti_supermanager'); + $class->setColumn('ccti_gosutitle as gosutitle', 'varchar', 50, array()); } } diff --git a/tests/Metadata/FactoryTestCase.php b/tests/Metadata/FactoryTestCase.php new file mode 100644 index 000000000..ac57a9999 --- /dev/null +++ b/tests/Metadata/FactoryTestCase.php @@ -0,0 +1,249 @@ +tables[] = 'Metadata_User'; + $this->tables[] = 'Metadata_Manager'; + $this->tables[] = 'Metadata_Customer'; + $this->tables[] = 'Metadata_SuperManager'; + parent::prepareTables(); + } + + public function setUp() + { + parent::setUp(); + $this->prepareTables(); + } + + public function testMetadataSetupOnClassTableInheritanceHierarchy() + { + $userClass = $this->conn->getMetadata('Metadata_User'); + $this->assertTrue($userClass instanceof Doctrine_ClassMetadata); + $this->assertEqual('cti_user', $userClass->getTableName()); + $this->assertEqual(4, count($userClass->getFields())); + $this->assertIdentical(array(), $userClass->getOption('parents')); + $this->assertEqual('type', $userClass->getInheritanceOption('discriminatorColumn')); + $this->assertIdentical(array( + 1 => 'CTI_User', + 2 => 'CTI_Manager', + 3 => 'CTI_Customer', + 4 => 'CTI_SuperManager'), $userClass->getInheritanceOption('discriminatorMap')); + + + $managerClass = $this->conn->getMetadata('Metadata_Manager'); + $this->assertTrue($managerClass instanceof Doctrine_ClassMetadata); + $this->assertIdentical(array('Metadata_User'), $managerClass->getOption('parents')); + $this->assertEqual('cti_manager', $managerClass->getTableName()); + $this->assertEqual(5, count($managerClass->getFields())); + $this->assertEqual('type', $managerClass->getInheritanceOption('discriminatorColumn')); + $this->assertIdentical(array( + 1 => 'CTI_User', + 2 => 'CTI_Manager', + 3 => 'CTI_Customer', + 4 => 'CTI_SuperManager'), $managerClass->getInheritanceOption('discriminatorMap')); + + + $suManagerClass = $this->conn->getMetadata('Metadata_SuperManager'); + $this->assertTrue($suManagerClass instanceof Doctrine_ClassMetadata); + $this->assertIdentical(array('Metadata_Manager', 'Metadata_User'), $suManagerClass->getOption('parents')); + $this->assertEqual('cti_supermanager', $suManagerClass->getTableName()); + $this->assertEqual(6, count($suManagerClass->getFields())); + $this->assertEqual('type', $suManagerClass->getInheritanceOption('discriminatorColumn')); + $this->assertIdentical(array( + 1 => 'CTI_User', + 2 => 'CTI_Manager', + 3 => 'CTI_Customer', + 4 => 'CTI_SuperManager'), $suManagerClass->getInheritanceOption('discriminatorMap')); + + //var_dump($suManagerClass->getColumns()); + } + + public function testExportableFormatOfClassInClassTableInheritanceHierarchy() + { + $userClass = $this->conn->getMetadata('Metadata_User'); + $userClassExportableFormat = $userClass->getExportableFormat(); + $this->assertEqual(4, count($userClassExportableFormat['columns'])); + $this->assertTrue(isset($userClassExportableFormat['columns']['cti_id'])); + $this->assertTrue(isset($userClassExportableFormat['columns']['cti_id']['primary'])); + $this->assertTrue(isset($userClassExportableFormat['columns']['cti_id']['autoincrement'])); + $this->assertTrue(isset($userClassExportableFormat['columns']['cti_foo'])); + $this->assertTrue(isset($userClassExportableFormat['columns']['cti_name'])); + $this->assertTrue(isset($userClassExportableFormat['columns']['type'])); + + $managerClass = $this->conn->getMetadata('Metadata_Manager'); + $managerClassExportableFormat = $managerClass->getExportableFormat(); + $this->assertEqual(2, count($managerClassExportableFormat['columns'])); + $this->assertTrue(isset($managerClassExportableFormat['columns']['cti_id'])); + $this->assertTrue(isset($managerClassExportableFormat['columns']['cti_id']['primary'])); + $this->assertFalse(isset($managerClassExportableFormat['columns']['cti_id']['autoincrement'])); + + $customerClass = $this->conn->getMetadata('Metadata_Customer'); + $customerClassExportableFormat = $customerClass->getExportableFormat(); + $this->assertEqual(2, count($customerClassExportableFormat['columns'])); + $this->assertTrue(isset($customerClassExportableFormat['columns']['cti_id'])); + $this->assertTrue(isset($customerClassExportableFormat['columns']['cti_id']['primary'])); + $this->assertFalse(isset($customerClassExportableFormat['columns']['cti_id']['autoincrement'])); + + $superManagerClass = $this->conn->getMetadata('Metadata_SuperManager'); + $superManagerClassExportableFormat = $superManagerClass->getExportableFormat(); + $this->assertEqual(2, count($superManagerClassExportableFormat['columns'])); + $this->assertTrue(isset($superManagerClassExportableFormat['columns']['cti_id'])); + $this->assertTrue(isset($superManagerClassExportableFormat['columns']['cti_id']['primary'])); + $this->assertFalse(isset($superManagerClassExportableFormat['columns']['cti_id']['autoincrement'])); + } + + public function testMetadataSetupOnSingleTableInheritanceHierarchy() + { + $userClass = $this->conn->getMetadata('Metadata_STI_User'); + $this->assertTrue($userClass instanceof Doctrine_ClassMetadata); + $this->assertEqual('cti_user', $userClass->getTableName()); + $this->assertEqual(4, count($userClass->getFields())); + $this->assertIdentical(array(), $userClass->getOption('parents')); + $this->assertEqual('type', $userClass->getInheritanceOption('discriminatorColumn')); + $this->assertIdentical(array( + 1 => 'CTI_User', + 2 => 'CTI_Manager', + 3 => 'CTI_Customer', + 4 => 'CTI_SuperManager'), $userClass->getInheritanceOption('discriminatorMap')); + + $managerClass = $this->conn->getMetadata('Metadata_STI_Manager'); + $this->assertTrue($managerClass instanceof Doctrine_ClassMetadata); + $this->assertIdentical(array('Metadata_STI_User'), $managerClass->getOption('parents')); + $this->assertEqual('cti_user', $managerClass->getTableName()); + $this->assertEqual(5, count($managerClass->getFields())); + $this->assertEqual('type', $managerClass->getInheritanceOption('discriminatorColumn')); + $this->assertIdentical(array( + 1 => 'CTI_User', + 2 => 'CTI_Manager', + 3 => 'CTI_Customer', + 4 => 'CTI_SuperManager'), $managerClass->getInheritanceOption('discriminatorMap')); + + + $suManagerClass = $this->conn->getMetadata('Metadata_STI_SuperManager'); + $this->assertTrue($suManagerClass instanceof Doctrine_ClassMetadata); + $this->assertIdentical(array('Metadata_STI_Manager', 'Metadata_STI_User'), $suManagerClass->getOption('parents')); + $this->assertEqual('cti_user', $suManagerClass->getTableName()); + $this->assertEqual(6, count($suManagerClass->getFields())); + $this->assertEqual('type', $suManagerClass->getInheritanceOption('discriminatorColumn')); + $this->assertIdentical(array( + 1 => 'CTI_User', + 2 => 'CTI_Manager', + 3 => 'CTI_Customer', + 4 => 'CTI_SuperManager'), $suManagerClass->getInheritanceOption('discriminatorMap')); + + //var_dump($suManagerClass->getColumns()); + } +} + + +class Metadata_User extends Doctrine_Record +{ + public static function initMetadata(Doctrine_ClassMetadata $class) + { + $class->setTableName('cti_user'); + $class->setInheritanceType(Doctrine::INHERITANCETYPE_JOINED, + array('discriminatorColumn' => 'type', + 'discriminatorMap' => array( + 1 => 'CTI_User', + 2 => 'CTI_Manager', + 3 => 'CTI_Customer', + 4 => 'CTI_SuperManager') + ) + ); + $class->setSubclasses(array('Metadata_Manager', 'Metadata_Customer', 'Metadata_SuperManager')); + $class->mapField('cti_id as id', 'integer', 4, array('primary' => true, 'autoincrement' => true)); + $class->mapField('cti_foo as foo', 'integer', 4); + $class->mapField('cti_name as name', 'string', 50); + $class->mapField('type', 'integer', 1); + + //$class->setNamedQuery('findByName', 'SELECT u.* FROM User u WHERE u.name = ?'); + } +} + +class Metadata_Manager extends Metadata_User +{ + public static function initMetadata(Doctrine_ClassMetadata $class) + { + $class->setTableName('cti_manager'); + $class->setSubclasses(array('Metadata_SuperManager')); + $class->mapField('ctim_salary as salary', 'varchar', 50, array()); + } +} + +class Metadata_Customer extends Metadata_User +{ + public static function initMetadata(Doctrine_ClassMetadata $class) + { + $class->setTableName('cti_customer'); + $class->setColumn('ctic_bonuspoints as bonuspoints', 'varchar', 50, array()); + } +} + +class Metadata_SuperManager extends Metadata_Manager +{ + public static function initMetadata(Doctrine_ClassMetadata $class) + { + $class->setTableName('cti_supermanager'); + $class->mapField('ctism_gosutitle as gosutitle', 'varchar', 50, array()); + } +} + + + +class Metadata_STI_User extends Doctrine_Record +{ + public static function initMetadata($class) + { + $class->setTableName('cti_user'); + $class->setInheritanceType(Doctrine::INHERITANCETYPE_SINGLE_TABLE, + array('discriminatorColumn' => 'type', + 'discriminatorMap' => array( + 1 => 'CTI_User', + 2 => 'CTI_Manager', + 3 => 'CTI_Customer', + 4 => 'CTI_SuperManager') + ) + ); + $class->setSubclasses(array('Metadata_STI_Manager', 'Metadata_STI_Customer', 'Metadata_STI_SuperManager')); + $class->mapField('cti_id as id', 'integer', 4, array('primary' => true, 'autoincrement' => true)); + $class->mapField('cti_foo as foo', 'integer', 4); + $class->mapField('cti_name as name', 'string', 50); + $class->mapField('type', 'integer', 1); + + //$class->setNamedQuery('findByName', 'SELECT u.* FROM User u WHERE u.name = ?'); + } +} + +class Metadata_STI_Manager extends Metadata_STI_User +{ + public static function initMetadata($class) + { + $class->setTableName('cti_manager'); + $class->setSubclasses(array('Metadata_STI_SuperManager')); + $class->mapField('ctim_salary as salary', 'varchar', 50, array()); + } +} + +class Metadata_STI_Customer extends Metadata_STI_User +{ + public static function initMetadata($class) + { + $class->setTableName('cti_customer'); + $class->setColumn('ctic_bonuspoints as bonuspoints', 'varchar', 50, array()); + } +} + +class Metadata_STI_SuperManager extends Metadata_STI_Manager +{ + public static function initMetadata($class) + { + $class->setTableName('cti_supermanager'); + $class->mapField('ctism_gosutitle as gosutitle', 'varchar', 50, array()); + } +} + diff --git a/tests/NestedSet/SingleRootTestCase.php b/tests/NestedSet/SingleRootTestCase.php index b3366555d..d0f1de783 100644 --- a/tests/NestedSet/SingleRootTestCase.php +++ b/tests/NestedSet/SingleRootTestCase.php @@ -42,7 +42,7 @@ class Doctrine_NestedSet_SingleRoot_TestCase extends Doctrine_UnitTestCase { $node = new NestedSetTest_SingleRootNode(); $node->name = 'root'; - $treeMngr = $this->conn->getTable('NestedSetTest_SingleRootNode')->getTree(); + $treeMngr = $this->conn->getMapper('NestedSetTest_SingleRootNode')->getTree(); $treeMngr->createRoot($node); $node2 = new NestedSetTest_SingleRootNode(); @@ -56,7 +56,7 @@ class Doctrine_NestedSet_SingleRoot_TestCase extends Doctrine_UnitTestCase public function testLftRgtValues() { - $treeMngr = $this->conn->getTable('NestedSetTest_SingleRootNode')->getTree(); + $treeMngr = $this->conn->getMapper('NestedSetTest_SingleRootNode')->getTree(); $root = $treeMngr->fetchRoot(); $this->assertEqual(1, $root['lft']); $this->assertEqual(6, $root['rgt']); @@ -64,7 +64,7 @@ class Doctrine_NestedSet_SingleRoot_TestCase extends Doctrine_UnitTestCase public function testGetDescendants() { - $treeMngr = $this->conn->getTable('NestedSetTest_SingleRootNode')->getTree(); + $treeMngr = $this->conn->getMapper('NestedSetTest_SingleRootNode')->getTree(); $root = $treeMngr->fetchRoot(); $desc = $root->getNode()->getDescendants(); $this->assertTrue($desc !== false); @@ -75,7 +75,7 @@ class Doctrine_NestedSet_SingleRoot_TestCase extends Doctrine_UnitTestCase public function testGetNumberChildren() { - $treeMngr = $this->conn->getTable('NestedSetTest_SingleRootNode')->getTree(); + $treeMngr = $this->conn->getMapper('NestedSetTest_SingleRootNode')->getTree(); $root = $treeMngr->fetchRoot(); $this->assertEqual(1, $root->getNode()->getNumberChildren()); } diff --git a/tests/Query/AggregateValueTestCase.php b/tests/Query/AggregateValueTestCase.php index d982c0bc7..89081a694 100644 --- a/tests/Query/AggregateValueTestCase.php +++ b/tests/Query/AggregateValueTestCase.php @@ -32,9 +32,13 @@ */ class Doctrine_Query_AggregateValue_TestCase extends Doctrine_UnitTestCase { - public function prepareData() - { + public function prepareTables() { + $this->tables = array('User', 'Phonenumber', 'QueryTest_Item'); + parent::prepareTables(); } + + public function prepareData() {} + public function testInitData() { $users = new Doctrine_Collection('User'); diff --git a/tests/Query/DeleteTestCase.php b/tests/Query/DeleteTestCase.php index d1f8a0683..4c4e17ed8 100644 --- a/tests/Query/DeleteTestCase.php +++ b/tests/Query/DeleteTestCase.php @@ -53,13 +53,13 @@ class Doctrine_Query_Delete_TestCase extends Doctrine_UnitTestCase $q->parseQuery('DELETE FROM Entity'); - $this->assertEqual($q->getQuery(), 'DELETE FROM entity'); + $this->assertEqual($q->getQuery(), 'DELETE FROM entity WHERE (type = 2 OR type = 1 OR type = 0)'); $q = new Doctrine_Query(); $q->delete()->from('Entity'); - $this->assertEqual($q->getQuery(), 'DELETE FROM entity'); + $this->assertEqual($q->getQuery(), 'DELETE FROM entity WHERE (type = 2 OR type = 1 OR type = 0)'); } public function testDeleteWithCondition() { @@ -67,13 +67,13 @@ class Doctrine_Query_Delete_TestCase extends Doctrine_UnitTestCase $q->parseQuery('DELETE FROM Entity WHERE id = 3'); - $this->assertEqual($q->getQuery(), 'DELETE FROM entity WHERE id = 3'); + $this->assertEqual($q->getQuery(), 'DELETE FROM entity WHERE id = 3 AND (type = 2 OR type = 1 OR type = 0)'); $q = new Doctrine_Query(); $q->delete()->from('Entity')->where('id = 3'); - $this->assertEqual($q->getQuery(), 'DELETE FROM entity WHERE id = 3'); + $this->assertEqual($q->getQuery(), 'DELETE FROM entity WHERE id = 3 AND (type = 2 OR type = 1 OR type = 0)'); } public function testDeleteWithLimit() { @@ -81,13 +81,13 @@ class Doctrine_Query_Delete_TestCase extends Doctrine_UnitTestCase $q->parseQuery('DELETE FROM Entity LIMIT 20'); - $this->assertEqual($q->getQuery(), 'DELETE FROM entity LIMIT 20'); + $this->assertEqual($q->getQuery(), 'DELETE FROM entity WHERE (type = 2 OR type = 1 OR type = 0) LIMIT 20'); $q = new Doctrine_Query(); $q->delete()->from('Entity')->limit(20); - $this->assertEqual($q->getQuery(), 'DELETE FROM entity LIMIT 20'); + $this->assertEqual($q->getQuery(), 'DELETE FROM entity WHERE (type = 2 OR type = 1 OR type = 0) LIMIT 20'); } public function testDeleteWithLimitAndOffset() { @@ -95,12 +95,12 @@ class Doctrine_Query_Delete_TestCase extends Doctrine_UnitTestCase $q->parseQuery('DELETE FROM Entity LIMIT 10 OFFSET 20'); - $this->assertEqual($q->getQuery(), 'DELETE FROM entity LIMIT 10 OFFSET 20'); + $this->assertEqual($q->getQuery(), 'DELETE FROM entity WHERE (type = 2 OR type = 1 OR type = 0) LIMIT 10 OFFSET 20'); $q = new Doctrine_Query(); $q->delete()->from('Entity')->limit(10)->offset(20); - $this->assertEqual($q->getQuery(), 'DELETE FROM entity LIMIT 10 OFFSET 20'); + $this->assertEqual($q->getQuery(), 'DELETE FROM entity WHERE (type = 2 OR type = 1 OR type = 0) LIMIT 10 OFFSET 20'); } } diff --git a/tests/Query/JoinCondition2TestCase.php b/tests/Query/JoinCondition2TestCase.php index 5101d139a..598a4135f 100755 --- a/tests/Query/JoinCondition2TestCase.php +++ b/tests/Query/JoinCondition2TestCase.php @@ -34,30 +34,38 @@ class Doctrine_Query_JoinCondition2_TestCase extends Doctrine_UnitTestCase { public function prepareTables() { - $this->tables[] = 'Entity'; - $this->tables[] = 'User'; - $this->tables[] = 'GroupUser'; - $this->tables[] = 'Group'; + $this->tables = array('User', 'Groupuser'); parent::prepareTables(); } public function prepareData() { - parent::prepareData(); - - $groups = new Doctrine_Collection('Group'); - - $groups[0]->name = 'PHP Users'; - - $groups[1]->name = 'Developers'; - - $groups->save(); - - $zYne = Doctrine_Query::create()->from('User u')->where('u.name = ?', 'zYne')->fetchOne(); - $zYne->Group[0] = $groups[0]; - $zYne->Group[1] = $groups[1]; + $this->conn->getMapper('User')->clear(); + $this->conn->getMapper('Group')->clear(); + $this->conn->getMapper('Groupuser')->clear(); + + $zYne = new User(); + $zYne->name = 'zYne'; $zYne->save(); + + $groups = new Doctrine_Collection('Group'); + $groups[0]->name = 'PHP Users'; + $groups[1]->name = 'Developers'; + //$groups->save(); + + $zYne->Group = $groups; + $zYne->save(); + + /*$q = new Doctrine_Query($this->connection); + $q->select('g.*')->from('Groupuser g'); + //echo $q->getSql(); + var_dump($q->execute(array(), Doctrine::HYDRATE_ARRAY)); + echo "

";*/ + + //$q = new Doctrine_Query($this->connection); + //$q->select('u.id, g.id')->from('User u')->leftJoin('u.Group g')->where('u.name = ?', 'zYne'); + //var_dump($q->execute(array(), Doctrine::HYDRATE_ARRAY)); } public function testJoinConditionsArgumentsLeftJoins() diff --git a/tests/Query/JoinTestCase.php b/tests/Query/JoinTestCase.php index f573247e3..89896b660 100644 --- a/tests/Query/JoinTestCase.php +++ b/tests/Query/JoinTestCase.php @@ -139,7 +139,7 @@ class Doctrine_Query_Join_TestCase extends Doctrine_UnitTestCase $q->select('e.name')->from('Entity e INNER JOIN e.Entity e2'); - $this->assertEqual($q->getQuery(), 'SELECT e.id AS e__id, e.name AS e__name FROM entity e INNER JOIN entity_reference e3 ON e.id = e3.entity1 OR e.id = e3.entity2 INNER JOIN entity e2 ON (e2.id = e3.entity2 OR e2.id = e3.entity1) AND e2.id != e.id'); + $this->assertEqual($q->getQuery(), 'SELECT e.id AS e__id, e.name AS e__name FROM entity e INNER JOIN entity_reference e3 ON e.id = e3.entity1 OR e.id = e3.entity2 INNER JOIN entity e2 ON (e2.id = e3.entity2 OR e2.id = e3.entity1) AND e2.id != e.id WHERE (e.type = 2 AND (e2.type = 2 OR e2.type IS NULL))'); } public function testMultipleJoins() diff --git a/tests/Query/MultipleAggregateValueTestCase.php b/tests/Query/MultipleAggregateValueTestCase.php index 1eb6f094b..ef23adb80 100644 --- a/tests/Query/MultipleAggregateValueTestCase.php +++ b/tests/Query/MultipleAggregateValueTestCase.php @@ -33,9 +33,13 @@ */ class Doctrine_Query_MultipleAggregateValue_TestCase extends Doctrine_UnitTestCase { + public function prepareTables() + { + $this->tables = array('User', 'Email', 'Album', 'Book'); + parent::prepareTables(); + } + public function prepareData() - { } - public function testInitData() { $user = new User(); $user->name = 'jon'; @@ -57,7 +61,7 @@ class Doctrine_Query_MultipleAggregateValue_TestCase extends Doctrine_UnitTestCa $query->leftJoin('u.Album a, u.Book b'); $query->where("u.name = 'jon'"); $query->limit(1); - + $user = $query->execute()->getFirst(); try { @@ -71,6 +75,7 @@ class Doctrine_Query_MultipleAggregateValue_TestCase extends Doctrine_UnitTestCa $this->assertEqual($num_albums, 3); $this->assertEqual($num_books, 2); } + public function testMultipleAggregateValuesWithArrayFetching() { $query = new Doctrine_Query(); diff --git a/tests/Query/SelectTestCase.php b/tests/Query/SelectTestCase.php index ae0c2ef70..1d5c98a60 100644 --- a/tests/Query/SelectTestCase.php +++ b/tests/Query/SelectTestCase.php @@ -32,7 +32,65 @@ */ class Doctrine_Query_Select_TestCase extends Doctrine_UnitTestCase { - /** + public function prepareTables() { + $this->tables = array('Email', 'Phonenumber', 'Entity', 'Groupuser'); + parent::prepareTables(); + } + + public function prepareData() { + + $groups = new Doctrine_Collection('Group'); + $groups[0]->name = 'Drama Actors'; + $groups[1]->name = 'Quality Actors'; + $groups[2]->name = 'Action Actors'; + $groups[2]['Phonenumber'][0]->phonenumber = '123 123'; + $groups->save(); + + $users = new Doctrine_Collection('User'); + + $users[0]->name = 'zYne'; + $users[0]['Email']->address = 'zYne@example.com'; + $users[0]['Phonenumber'][0]->phonenumber = '123 123'; + + $users[1]->name = 'Arnold Schwarzenegger'; + $users[1]->Email->address = 'arnold@example.com'; + $users[1]['Phonenumber'][0]->phonenumber = '123 123'; + $users[1]['Phonenumber'][1]->phonenumber = '456 456'; + $users[1]->Phonenumber[2]->phonenumber = '789 789'; + $users[1]->Group[0] = $groups[2]; + + $users[2]->name = 'Michael Caine'; + $users[2]->Email->address = 'caine@example.com'; + $users[2]->Phonenumber[0]->phonenumber = '123 123'; + + $users[3]->name = 'Takeshi Kitano'; + $users[3]->Email->address = 'kitano@example.com'; + $users[3]->Phonenumber[0]->phonenumber = '111 222 333'; + + $users[4]->name = 'Sylvester Stallone'; + $users[4]->Email->address = 'stallone@example.com'; + $users[4]->Phonenumber[0]->phonenumber = '111 555 333'; + $users[4]['Phonenumber'][1]->phonenumber = '123 213'; + $users[4]['Phonenumber'][2]->phonenumber = '444 555'; + + $users[5]->name = 'Kurt Russell'; + $users[5]->Email->address = 'russell@example.com'; + $users[5]->Phonenumber[0]->phonenumber = '111 222 333'; + + $users[6]->name = 'Jean Reno'; + $users[6]->Email->address = 'reno@example.com'; + $users[6]->Phonenumber[0]->phonenumber = '111 222 333'; + $users[6]['Phonenumber'][1]->phonenumber = '222 123'; + $users[6]['Phonenumber'][2]->phonenumber = '123 456'; + + $users[7]->name = 'Edward Furlong'; + $users[7]->Email->address = 'furlong@example.com'; + $users[7]->Phonenumber[0]->phonenumber = '111 567 333'; + + $users->save(); + } + + /* public function testParseSelect() { $q = new Doctrine_Query(); @@ -134,7 +192,7 @@ class Doctrine_Query_Select_TestCase extends Doctrine_UnitTestCase $this->pass(); } } - + /* public function testAggregateFunctionValueHydration() { $q = new Doctrine_Query(); @@ -159,6 +217,7 @@ class Doctrine_Query_Select_TestCase extends Doctrine_UnitTestCase $this->assertEqual($q->getQuery(), 'SELECT e.id AS e__id, e.name AS e__name, e.loginname AS e__loginname, e.password AS e__password, e.type AS e__type, e.created AS e__created, e.updated AS e__updated, e.email_id AS e__email_id FROM entity e WHERE (e.type = 0)'); } + public function testSingleComponentWithMultipleColumns() { $q = new Doctrine_Query(); @@ -167,6 +226,7 @@ class Doctrine_Query_Select_TestCase extends Doctrine_UnitTestCase $this->assertEqual($q->getQuery(), 'SELECT e.id AS e__id, e.name AS e__name, e.type AS e__type FROM entity e WHERE (e.type = 0)'); } + public function testMultipleComponentsWithAsterisk() { $q = new Doctrine_Query(); @@ -175,6 +235,7 @@ class Doctrine_Query_Select_TestCase extends Doctrine_UnitTestCase $this->assertEqual($q->getQuery(),'SELECT e.id AS e__id, e.name AS e__name, e.loginname AS e__loginname, e.password AS e__password, e.type AS e__type, e.created AS e__created, e.updated AS e__updated, e.email_id AS e__email_id, p.id AS p__id, p.phonenumber AS p__phonenumber, p.entity_id AS p__entity_id FROM entity e LEFT JOIN phonenumber p ON e.id = p.entity_id WHERE (e.type = 0)'); } + public function testMultipleComponentsWithMultipleColumns() { $q = new Doctrine_Query(); @@ -183,6 +244,7 @@ class Doctrine_Query_Select_TestCase extends Doctrine_UnitTestCase $this->assertEqual($q->getQuery(),'SELECT e.id AS e__id, e.name AS e__name, p.id AS p__id FROM entity e LEFT JOIN phonenumber p ON e.id = p.entity_id WHERE (e.type = 0)'); } + public function testAggregateFunctionValueHydrationWithAliases() { @@ -198,6 +260,7 @@ class Doctrine_Query_Select_TestCase extends Doctrine_UnitTestCase $this->assertEqual($users[3]->Phonenumber[0]->count, 1); $this->assertEqual($users[4]->Phonenumber[0]->count, 3); } + public function testMultipleAggregateFunctionValueHydrationWithAliases() { $q = new Doctrine_Query(); @@ -217,6 +280,7 @@ class Doctrine_Query_Select_TestCase extends Doctrine_UnitTestCase $this->assertEqual($users[3]->Phonenumber[0]->max, '111 222 333'); $this->assertEqual($users[4]->Phonenumber[0]->max, '444 555'); } + public function testMultipleAggregateFunctionValueHydrationWithAliasesAndCleanRecords() { $this->connection->clear(); @@ -242,6 +306,6 @@ class Doctrine_Query_Select_TestCase extends Doctrine_UnitTestCase $this->assertEqual($users[2]->Phonenumber[0]->max, '123 123'); $this->assertEqual($users[3]->Phonenumber[0]->max, '111 222 333'); $this->assertEqual($users[4]->Phonenumber[0]->max, '444 555'); - } + }*/ } diff --git a/tests/Query/WhereTestCase.php b/tests/Query/WhereTestCase.php index 8e5ab48cc..da87bcae5 100644 --- a/tests/Query/WhereTestCase.php +++ b/tests/Query/WhereTestCase.php @@ -37,7 +37,7 @@ class Doctrine_Query_Where_TestCase extends Doctrine_UnitTestCase { } public function prepareTables() { - $this->tables = array('Entity', 'EnumTest', 'GroupUser', 'Account', 'Book'); + $this->tables = array('Entity', 'EnumTest', 'Groupuser', 'Account', 'Book'); parent::prepareTables(); } diff --git a/tests/QueryTestCase.php b/tests/QueryTestCase.php index dbdb42ed5..3519d91b5 100644 --- a/tests/QueryTestCase.php +++ b/tests/QueryTestCase.php @@ -58,6 +58,7 @@ class Doctrine_Query_TestCase extends Doctrine_UnitTestCase $this->assertEqual($str, '2 + 3 - 5 * 6'); } + public function testParseClauseSupportsArithmeticOperatorsWithFunctions() { $q = new Doctrine_Query(); diff --git a/tests/RawSqlTestCase.php b/tests/RawSqlTestCase.php index a58547b9e..055396e96 100644 --- a/tests/RawSqlTestCase.php +++ b/tests/RawSqlTestCase.php @@ -49,6 +49,7 @@ class Doctrine_RawSql_TestCase extends Doctrine_UnitTestCase $this->assertEqual($query->getQueryPart('where'), array('p.can_see = -1 AND t.tag_id = 62')); $this->assertEqual($query->getQueryPart('limit'), array(200)); } + public function testAsteriskOperator() { // Selecting with * @@ -65,6 +66,7 @@ class Doctrine_RawSql_TestCase extends Doctrine_UnitTestCase $this->assertEqual($coll->count(), 11); } + public function testLazyPropertyLoading() { $query = new Doctrine_RawSql($this->connection); @@ -222,7 +224,7 @@ class Doctrine_RawSql_TestCase extends Doctrine_UnitTestCase $query->parseQuery("SELECT {entity.name} FROM (SELECT entity.name FROM entity WHERE entity.name = 'something') WHERE entity.id = 2 ORDER BY entity.name"); $this->assertEqual($query->getQuery(), - "SELECT entity.name AS entity__name, entity.id AS entity__id FROM (SELECT entity.name FROM entity WHERE entity.name = 'something') WHERE entity.id = 2 ORDER BY entity.name"); + "SELECT entity.name AS entity__name, entity.id AS entity__id FROM (SELECT entity.name FROM entity WHERE entity.name = 'something') WHERE entity.id = 2 AND (entity.type = 2 OR entity.type = 1 OR entity.type = 0) ORDER BY entity.name"); } public function testSelectingWithoutIdentifiersOnRootComponent() @@ -232,7 +234,7 @@ class Doctrine_RawSql_TestCase extends Doctrine_UnitTestCase $query->parseQuery('SELECT {entity.name}, {phonenumber.*} FROM entity LEFT JOIN phonenumber ON phonenumber.entity_id = entity.id LIMIT 3'); $query->addComponent('entity', 'Entity'); $query->addComponent('phonenumber', 'Entity.Phonenumber'); - $this->assertEqual($query->getSql(), 'SELECT entity.name AS entity__name, entity.id AS entity__id, phonenumber.id AS phonenumber__id, phonenumber.phonenumber AS phonenumber__phonenumber, phonenumber.entity_id AS phonenumber__entity_id FROM entity LEFT JOIN phonenumber ON phonenumber.entity_id = entity.id LIMIT 3'); + $this->assertEqual($query->getSql(), 'SELECT entity.name AS entity__name, entity.id AS entity__id, phonenumber.id AS phonenumber__id, phonenumber.phonenumber AS phonenumber__phonenumber, phonenumber.entity_id AS phonenumber__entity_id FROM entity LEFT JOIN phonenumber ON phonenumber.entity_id = entity.id WHERE (entity.type = 2 OR entity.type = 1 OR entity.type = 0) LIMIT 3'); $coll = $query->execute(array(), Doctrine::FETCH_ARRAY); $this->assertEqual(count($coll), 3); @@ -245,7 +247,7 @@ class Doctrine_RawSql_TestCase extends Doctrine_UnitTestCase $query->parseQuery('SELECT {phonenumber.*}, {entity.name} FROM entity LEFT JOIN phonenumber ON phonenumber.entity_id = entity.id LIMIT 3'); $query->addComponent('entity', 'Entity'); $query->addComponent('phonenumber', 'Entity.Phonenumber'); - $this->assertEqual($query->getSql(), 'SELECT entity.name AS entity__name, entity.id AS entity__id, phonenumber.id AS phonenumber__id, phonenumber.phonenumber AS phonenumber__phonenumber, phonenumber.entity_id AS phonenumber__entity_id FROM entity LEFT JOIN phonenumber ON phonenumber.entity_id = entity.id LIMIT 3'); + $this->assertEqual($query->getSql(), 'SELECT entity.name AS entity__name, entity.id AS entity__id, phonenumber.id AS phonenumber__id, phonenumber.phonenumber AS phonenumber__phonenumber, phonenumber.entity_id AS phonenumber__entity_id FROM entity LEFT JOIN phonenumber ON phonenumber.entity_id = entity.id WHERE (entity.type = 2 OR entity.type = 1 OR entity.type = 0) LIMIT 3'); $coll = $query->execute(array(), Doctrine::FETCH_ARRAY); $this->assertEqual(count($coll), 3); diff --git a/tests/Record/FilterTestCase.php b/tests/Record/FilterTestCase.php index 9c1eda2c9..a7b015355 100644 --- a/tests/Record/FilterTestCase.php +++ b/tests/Record/FilterTestCase.php @@ -86,22 +86,19 @@ class Doctrine_Record_Filter_TestCase extends Doctrine_UnitTestCase } class CompositeRecord extends Doctrine_Record { - public function setTableDefinition() + public static function initMetadata($class) { - $this->hasColumn('name', 'string'); - } - public function setUp() - { - $this->hasOne('RelatedCompositeRecord as Related', array('foreign' => 'foreign_id')); + $class->setColumn('name', 'string'); + $class->hasOne('RelatedCompositeRecord as Related', array('local' => 'id', 'foreign' => 'foreign_id')); - $this->unshiftFilter(new Doctrine_Record_Filter_Compound(array('Related'))); + $class->unshiftFilter(new Doctrine_Record_Filter_Compound(array('Related'))); } } class RelatedCompositeRecord extends Doctrine_Record { - public function setTableDefinition() + public static function initMetadata($class) { - $this->hasColumn('address', 'string'); - $this->hasColumn('foreign_id', 'integer'); + $class->setColumn('address', 'string'); + $class->setColumn('foreign_id', 'integer'); } } diff --git a/tests/RecordTestCase.php b/tests/RecordTestCase.php index 5efaa0c05..7f68d92eb 100644 --- a/tests/RecordTestCase.php +++ b/tests/RecordTestCase.php @@ -397,7 +397,7 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase public function testNewOperator() { - $table = $this->connection->getTable("User"); + $table = $this->connection->getClassMetadata("User"); $this->assertEqual($this->connection->getMapper("User")->getData(), array()); $user = new User(); @@ -489,7 +489,7 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase $this->assertTrue($fk instanceof Doctrine_Relation_ForeignKey); $this->assertEqual($fk->getLocal(),'file_md5'); $this->assertEqual($fk->getForeign(),'file_md5'); - $this->assertTrue($fk->getTable() instanceof Doctrine_Table); + $this->assertTrue($fk->getTable() instanceof Doctrine_ClassMetadata); $e->Description[0]->description = 'This is the 1st description'; $e->Description[1]->description = 'This is the 2nd description'; @@ -744,13 +744,11 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase $user = $userMapper->find(5); $this->assertTrue($userMapper === $user->getMapper()); $this->assertTrue($userMapper->getTable() === $user->getMapper()->getTable()); - $this->assertTrue($userMapper->getTable() === $this->conn->getTable('User')); + $this->assertTrue($userMapper->getTable() === $this->conn->getClassMetadata('User')); $this->assertTrue($this->conn === $userMapper->getConnection()); $userTable = $userMapper->getTable(); - $rel1 = $userTable->getRelation('GroupGroupuser'); - $rel2 = $userTable->getRelation('UserGroupuser'); /*echo get_class($rel1) . "
"; echo get_class($rel2) . "
"; echo get_class($userTable->getRelation('Group')); @@ -844,27 +842,27 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase // ACCESSING ASSOCIATION OBJECT PROPERTIES $user = new User(); - $this->assertTrue($user->getTable()->getRelation("UserGroupuser") instanceof Doctrine_Relation_ForeignKey); + $this->assertTrue($user->getTable()->getRelation("Groupuser") instanceof Doctrine_Relation_ForeignKey); - $this->assertTrue($user->UserGroupuser instanceof Doctrine_Collection); - $this->assertTrue($user->UserGroupuser[0] instanceof Groupuser); + $this->assertTrue($user->Groupuser instanceof Doctrine_Collection); + $this->assertTrue($user->Groupuser[0] instanceof Groupuser); $user->name = "Jack Daniels"; $user->Group[0]->name = "Group #1"; $user->Group[1]->name = "Group #2"; $t1 = time(); $t2 = time(); - $user->UserGroupuser[0]->added = $t1; - $user->UserGroupuser[1]->added = $t2; + $user->Groupuser[0]->added = $t1; + $user->Groupuser[1]->added = $t2; - $this->assertEqual($user->UserGroupuser[0]->added, $t1); - $this->assertEqual($user->UserGroupuser[1]->added, $t2); + $this->assertEqual($user->Groupuser[0]->added, $t1); + $this->assertEqual($user->Groupuser[1]->added, $t2); $user->save(); $user->refresh(); - $this->assertEqual($user->UserGroupuser[0]->added, $t1); - $this->assertEqual($user->UserGroupuser[1]->added, $t2); + $this->assertEqual($user->Groupuser[0]->added, $t1); + $this->assertEqual($user->Groupuser[1]->added, $t2); } diff --git a/tests/Relation/OneToManyTestCase.php b/tests/Relation/OneToManyTestCase.php index 587d75733..de9e36bd1 100644 --- a/tests/Relation/OneToManyTestCase.php +++ b/tests/Relation/OneToManyTestCase.php @@ -42,7 +42,7 @@ class Doctrine_Relation_OneToMany_TestCase extends Doctrine_UnitTestCase } public function testRelationParsing() { - $table = $this->conn->getTable('Entity'); + $table = $this->conn->getClassMetadata('Entity'); $rel = $table->getRelation('Phonenumber'); @@ -55,7 +55,7 @@ class Doctrine_Relation_OneToMany_TestCase extends Doctrine_UnitTestCase public function testRelationParsing2() { - $table = $this->conn->getTable('Phonenumber'); + $table = $this->conn->getClassMetadata('Phonenumber'); $rel = $table->getRelation('Entity'); @@ -64,7 +64,7 @@ class Doctrine_Relation_OneToMany_TestCase extends Doctrine_UnitTestCase public function testRelationParsing3() { - $table = $this->conn->getTable('Policy'); + $table = $this->conn->getClassMetadata('Policy'); $rel = $table->getRelation('PolicyAssets'); diff --git a/tests/Relation/ParserTestCase.php b/tests/Relation/ParserTestCase.php index 937f99a44..fd3fd64a1 100644 --- a/tests/Relation/ParserTestCase.php +++ b/tests/Relation/ParserTestCase.php @@ -34,7 +34,7 @@ class Doctrine_Relation_Parser_TestCase extends Doctrine_UnitTestCase { public function testPendingRelations() { - $r = new Doctrine_Relation_Parser($this->conn->getTable('User')); + $r = new Doctrine_Relation_Parser($this->conn->getClassMetadata('User')); $p = array('type' => Doctrine_Relation::ONE, 'local' => 'email_id'); @@ -49,7 +49,7 @@ class Doctrine_Relation_Parser_TestCase extends Doctrine_UnitTestCase } public function testBindThrowsExceptionIfTypeNotSet() { - $r = new Doctrine_Relation_Parser($this->conn->getTable('User')); + $r = new Doctrine_Relation_Parser($this->conn->getClassMetadata('User')); $p = array('local' => 'email_id'); try { @@ -61,7 +61,7 @@ class Doctrine_Relation_Parser_TestCase extends Doctrine_UnitTestCase } public function testRelationParserSupportsLocalColumnGuessing() { - $r = new Doctrine_Relation_Parser($this->conn->getTable('User')); + $r = new Doctrine_Relation_Parser($this->conn->getClassMetadata('User')); $d = $r->completeDefinition(array('class' => 'Phonenumber', 'type' => Doctrine_Relation::MANY, @@ -71,7 +71,7 @@ class Doctrine_Relation_Parser_TestCase extends Doctrine_UnitTestCase } public function testRelationParserSupportsLocalColumnGuessing2() { - $r = new Doctrine_Relation_Parser($this->conn->getTable('User')); + $r = new Doctrine_Relation_Parser($this->conn->getClassMetadata('User')); $d = $r->completeDefinition(array('class' => 'Email', 'type' => Doctrine_Relation::ONE, @@ -81,7 +81,7 @@ class Doctrine_Relation_Parser_TestCase extends Doctrine_UnitTestCase } public function testRelationParserSupportsForeignColumnGuessing() { - $r = new Doctrine_Relation_Parser($this->conn->getTable('User')); + $r = new Doctrine_Relation_Parser($this->conn->getClassMetadata('User')); $d = $r->completeDefinition(array('class' => 'Phonenumber', 'type' => Doctrine_Relation::MANY, @@ -91,7 +91,7 @@ class Doctrine_Relation_Parser_TestCase extends Doctrine_UnitTestCase } public function testRelationParserSupportsForeignColumnGuessing2() { - $r = new Doctrine_Relation_Parser($this->conn->getTable('User')); + $r = new Doctrine_Relation_Parser($this->conn->getClassMetadata('User')); $d = $r->completeDefinition(array('class' => 'Email', 'type' => Doctrine_Relation::ONE, @@ -101,7 +101,7 @@ class Doctrine_Relation_Parser_TestCase extends Doctrine_UnitTestCase } public function testRelationParserSupportsGuessingOfBothColumns() { - $r = new Doctrine_Relation_Parser($this->conn->getTable('User')); + $r = new Doctrine_Relation_Parser($this->conn->getClassMetadata('User')); $d = $r->completeDefinition(array('class' => 'Email', 'type' => Doctrine_Relation::ONE)); @@ -112,7 +112,7 @@ class Doctrine_Relation_Parser_TestCase extends Doctrine_UnitTestCase public function testRelationParserSupportsGuessingOfBothColumns2() { - $r = new Doctrine_Relation_Parser($this->conn->getTable('User')); + $r = new Doctrine_Relation_Parser($this->conn->getClassMetadata('User')); $d = $r->completeDefinition(array('class' => 'Phonenumber', 'type' => Doctrine_Relation::MANY)); @@ -138,14 +138,14 @@ class Doctrine_Relation_Parser_TestCase extends Doctrine_UnitTestCase $d = $r->completeAssocDefinition(array('class' => 'Group', 'type' => Doctrine_Relation::MANY, 'foreign' => 'group_id', - 'refClass' => 'GroupUser')); + 'refClass' => 'Groupuser')); $this->assertEqual($d['local'], 'user_id'); }*/ public function testGetRelationReturnsForeignKeyObjectForOneToOneRelation() { - $r = new Doctrine_Relation_Parser($this->conn->getTable('User')); + $r = new Doctrine_Relation_Parser($this->conn->getClassMetadata('User')); $p = array('type' => Doctrine_Relation::ONE, 'local' => 'email_id'); @@ -155,9 +155,10 @@ class Doctrine_Relation_Parser_TestCase extends Doctrine_UnitTestCase $this->assertTrue($rel instanceof Doctrine_Relation_LocalKey); } + public function testGetRelationReturnsForeignKeyObjectForOneToManyRelation() { - $r = new Doctrine_Relation_Parser($this->conn->getTable('User')); + $r = new Doctrine_Relation_Parser($this->conn->getClassMetadata('User')); $p = array('type' => Doctrine_Relation::MANY); $r->bind('Phonenumber', $p); @@ -166,24 +167,23 @@ class Doctrine_Relation_Parser_TestCase extends Doctrine_UnitTestCase $this->assertTrue($rel instanceof Doctrine_Relation_ForeignKey); } + public function testGetRelationReturnsForeignKeyObjectForManytToManyRelation() { - $r = new Doctrine_Relation_Parser($this->conn->getTable('User')); - $p = array('type' => Doctrine_Relation::MANY, 'refClass' => 'GroupUser', - 'refRelationName' => 'UserGroupuser', - 'refReverseRelationName' => 'GroupGroupuser'); + $r = new Doctrine_Relation_Parser($this->conn->getClassMetadata('User')); + $p = array('type' => Doctrine_Relation::MANY, 'refClass' => 'Groupuser'); $r->bind('Group', $p); $rel = $r->getRelation('Group'); $this->assertTrue($rel instanceof Doctrine_Relation_Association); - $rel = $r->getRelation('UserGroupuser'); + $rel = $r->getRelation('Groupuser'); $this->assertTrue($rel instanceof Doctrine_Relation_ForeignKey); } public function testGetRelationReturnsForeignKeyObjectForNestRelation() { - $r = new Doctrine_Relation_Parser($this->conn->getTable('Entity')); + $r = new Doctrine_Relation_Parser($this->conn->getClassMetadata('Entity')); $p = array('type' => Doctrine_Relation::MANY, 'refClass' => 'EntityReference', 'local' => 'entity1', diff --git a/tests/RelationTestCase.php b/tests/RelationTestCase.php index ae2232214..a6dc482f4 100644 --- a/tests/RelationTestCase.php +++ b/tests/RelationTestCase.php @@ -77,7 +77,7 @@ class Doctrine_Relation_TestCase extends Doctrine_UnitTestCase $this->assertEqual($groups->count(), 3); - $links = Doctrine_Query::create()->from('GroupUser gu')->execute(); + $links = Doctrine_Query::create()->from('Groupuser gu')->execute(); $this->assertEqual($links->count(), 0); } @@ -140,7 +140,7 @@ class Doctrine_Relation_TestCase extends Doctrine_UnitTestCase // test that join table relations can be initialized even before the association have been initialized try { - $user->UserGroupuser; + $user->Groupuser; $this->pass(); } catch(Doctrine_Exception $e) { $this->fail(); diff --git a/tests/TableTestCase.php b/tests/TableTestCase.php index 15d56bd00..fd28eaebe 100644 --- a/tests/TableTestCase.php +++ b/tests/TableTestCase.php @@ -98,22 +98,24 @@ class Doctrine_Table_TestCase extends Doctrine_UnitTestCase { $fk = $this->objTable->getTable()->getRelation("Group"); $this->assertTrue($fk instanceof Doctrine_Relation_Association); - $this->assertTrue($fk->getTable() instanceof Doctrine_Table); + $this->assertTrue($fk->getTable() instanceof Doctrine_ClassMetadata); $this->assertTrue($fk->getType() == Doctrine_Relation::MANY_AGGREGATE); $this->assertTrue($fk->getLocal() == "user_id"); $this->assertTrue($fk->getForeign() == "group_id"); $fk = $this->objTable->getTable()->getRelation("Email"); $this->assertTrue($fk instanceof Doctrine_Relation_LocalKey); - $this->assertTrue($fk->getTable() instanceof Doctrine_Table); + + $this->assertTrue($fk->getTable() instanceof Doctrine_ClassMetadata); $this->assertTrue($fk->getType() == Doctrine_Relation::ONE_AGGREGATE); + $this->assertTrue($fk->getLocal() == "email_id"); $this->assertTrue($fk->getForeign() == $fk->getTable()->getIdentifier()); $fk = $this->objTable->getTable()->getRelation('Phonenumber'); $this->assertTrue($fk instanceof Doctrine_Relation_ForeignKey); - $this->assertTrue($fk->getTable() instanceof Doctrine_Table); + $this->assertTrue($fk->getTable() instanceof Doctrine_ClassMetadata); $this->assertTrue($fk->getType() == Doctrine_Relation::MANY); $this->assertTrue($fk->getLocal() == $this->objTable->getTable()->getIdentifier()); $this->assertTrue($fk->getForeign() == 'entity_id'); diff --git a/tests/Ticket/428TestCase.php b/tests/Ticket/428TestCase.php index 1a560a0fa..79bbdef3b 100644 --- a/tests/Ticket/428TestCase.php +++ b/tests/Ticket/428TestCase.php @@ -13,6 +13,12 @@ */ class Doctrine_Ticket_428_TestCase extends Doctrine_UnitTestCase { + public function prepareTables() + { + $this->tables = array('Album', 'Song'); + parent::prepareTables(); + } + public function prepareData() { } @@ -38,7 +44,7 @@ class Doctrine_Ticket_428_TestCase extends Doctrine_UnitTestCase $q->select('a.name, COUNT(s.id) count')->from('Album a')->leftJoin('a.Song s')->groupby('a.id'); $albums = $q->execute(); - + // Should not reuse the existing collection in this case $this->assertEqual(count($albums[0]->Song), 1); diff --git a/tests/Ticket/438TestCase.php b/tests/Ticket/438TestCase.php index b8d5b9f42..fd1cc69ac 100644 --- a/tests/Ticket/438TestCase.php +++ b/tests/Ticket/438TestCase.php @@ -109,51 +109,36 @@ class Doctrine_Ticket_438_TestCase extends Doctrine_UnitTestCase class T438_Student extends Doctrine_Record { - public function setTableDefinition() + public static function initMetadata($class) { - $this->setTableName('t438_student_record'); - - $this->hasColumn('s_id as id', 'varchar', 30, array ( 'primary' => true,)); - $this->hasColumn('s_name as name', 'varchar', 50, array ()); - } - - public function setUp() - { - $this->hasMany('T438_Course as StudyCourses', array('refClass' => 'T438_StudentCourse', 'local' => 'sc_student_id', 'foreign' => 'sc_course_id')); + $class->setTableName('t438_student_record'); + $class->setColumn('s_id as id', 'varchar', 30, array ( 'primary' => true,)); + $class->setColumn('s_name as name', 'varchar', 50, array ()); + $class->hasMany('T438_Course as StudyCourses', array('refClass' => 'T438_StudentCourse', 'local' => 'sc_student_id', 'foreign' => 'sc_course_id')); } } class T438_Course extends Doctrine_Record { - public function setTableDefinition() + public static function initMetadata($class) { - $this->setTableName('t438_course'); - - $this->hasColumn('c_id as id', 'varchar', 20, array ( 'primary' => true,)); - $this->hasColumn('c_name as name', 'varchar', 50, array ()); - } - - public function setUp() - { - $this->hasMany('T438_Student as Students', array('refClass' => 'T438_StudentCourse', 'local' => 'sc_course_id', 'foreign' => 'sc_student_id')); + $class->setTableName('t438_course'); + $class->setColumn('c_id as id', 'varchar', 20, array ( 'primary' => true,)); + $class->setColumn('c_name as name', 'varchar', 50, array ()); + $class->hasMany('T438_Student as Students', array('refClass' => 'T438_StudentCourse', 'local' => 'sc_course_id', 'foreign' => 'sc_student_id')); } } class T438_StudentCourse extends Doctrine_Record { - public function setTableDefinition() + public static function initMetadata($class) { - $this->setTableName('t438_student_course'); - - $this->hasColumn('sc_student_id as student_id', 'varchar', 30, array ( 'primary' => true,)); - $this->hasColumn('sc_course_id as course_id', 'varchar', 20, array ( 'primary' => true,)); - $this->hasColumn('sc_remark as remark', 'varchar', 500, array ()); - } - - public function setUp() - { - $this->hasOne('T438_Student as Student', array('local' => 'sc_student_id', 'foreign' => 's_id')); - $this->hasOne('T438_Course as Course', array('local' => 'sc_course_id', 'foreign' => 'c_id')); + $class->setTableName('t438_student_course'); + $class->setColumn('sc_student_id as student_id', 'varchar', 30, array ( 'primary' => true,)); + $class->setColumn('sc_course_id as course_id', 'varchar', 20, array ( 'primary' => true,)); + $class->setColumn('sc_remark as remark', 'varchar', 500, array ()); + $class->hasOne('T438_Student as Student', array('local' => 'sc_student_id', 'foreign' => 's_id')); + $class->hasOne('T438_Course as Course', array('local' => 'sc_course_id', 'foreign' => 'c_id')); } } diff --git a/tests/Ticket/480TestCase.php b/tests/Ticket/480TestCase.php index c253d8190..03856e461 100644 --- a/tests/Ticket/480TestCase.php +++ b/tests/Ticket/480TestCase.php @@ -33,11 +33,11 @@ class stComment extends Doctrine_Record { - public function setTableDefinition() + public static function initMetadata($class) { - $this->setTableName('st_comment'); - $this->hasColumn('title', 'string', 100, array()); - $this->hasColumn('body', 'string', 1000, array()); + $class->setTableName('st_comment'); + $class->setColumn('title', 'string', 100, array()); + $class->setColumn('body', 'string', 1000, array()); } } diff --git a/tests/Ticket/626BTestCase.php b/tests/Ticket/626BTestCase.php index d15580982..a4044f4e6 100644 --- a/tests/Ticket/626BTestCase.php +++ b/tests/Ticket/626BTestCase.php @@ -90,70 +90,55 @@ class Doctrine_Ticket_626B_TestCase extends Doctrine_UnitTestCase class T626B_Student extends Doctrine_Record { - public function setTableDefinition() + public static function initMetadata($class) { - $this->setTableName('T626B_Student_record'); + $class->setTableName('T626B_Student_record'); - $this->hasColumn('s_id as id', 'varchar', 30, array ( 'primary' => true,)); - $this->hasColumn('s_g_id as group_id', 'varchar', 30, array ('notnull'=>true)); - $this->hasColumn('s_name as name', 'varchar', 50, array ()); - } - - public function setUp() - { - $this->hasMany('T626_Course as StudyCourses', array('refClass' => 'T626B_StudentCourse', 'local' => 'sc_student_id', 'foreign' => 'sc_course_id')); - $this->hasOne('T626_Group as Group', array('local' => 's_g_id', 'foreign' => 'g_id')); + $class->setColumn('s_id as id', 'varchar', 30, array ( 'primary' => true,)); + $class->setColumn('s_g_id as group_id', 'varchar', 30, array ('notnull'=>true)); + $class->setColumn('s_name as name', 'varchar', 50, array ()); + + $class->hasMany('T626_Course as StudyCourses', array('refClass' => 'T626B_StudentCourse', 'local' => 'sc_student_id', 'foreign' => 'sc_course_id')); + $class->hasOne('T626_Group as Group', array('local' => 's_g_id', 'foreign' => 'g_id')); } } class T626_Group extends Doctrine_Record { - public function setTableDefinition() + public static function initMetadata($class) { - $this->setTableName('T626B_Student_group'); + $class->setTableName('T626B_Student_group'); - $this->hasColumn('g_id as id', 'varchar', 30, array ( 'primary' => true,)); - $this->hasColumn('g_name as name', 'varchar', 50, array ()); - } - - public function setUp() - { - $this->hasMany('T626B_Student as Students', - array('local' => 'g_id', 'foreign' => 's_id')); + $class->setColumn('g_id as id', 'varchar', 30, array ( 'primary' => true,)); + $class->setColumn('g_name as name', 'varchar', 50, array ()); + + $class->hasMany('T626B_Student as Students', array('local' => 'g_id', 'foreign' => 's_id')); } } class T626_Course extends Doctrine_Record { - public function setTableDefinition() + public static function initMetadata($class) { - $this->setTableName('T626_course'); + $class->setTableName('T626_course'); - $this->hasColumn('c_id as id', 'varchar', 20, array ( 'primary' => true,)); - $this->hasColumn('c_name as name', 'varchar', 50, array ()); - } - - public function setUp() - { - $this->hasMany('T626B_Student as Students', array('refClass' => 'T626B_StudentCourse', 'local' => 'sc_course_id', 'foreign' => 'sc_student_id')); + $class->setColumn('c_id as id', 'varchar', 20, array ( 'primary' => true,)); + $class->setColumn('c_name as name', 'varchar', 50, array ()); + $class->hasMany('T626B_Student as Students', array('refClass' => 'T626B_StudentCourse', 'local' => 'sc_course_id', 'foreign' => 'sc_student_id')); } } class T626B_StudentCourse extends Doctrine_Record { - public function setTableDefinition() + public static function initMetadata($class) { - $this->setTableName('T626B_Student_course'); + $class->setTableName('T626B_Student_course'); - $this->hasColumn('sc_student_id as student_id', 'varchar', 30, array ( 'primary' => true,)); - $this->hasColumn('sc_course_id as course_id', 'varchar', 20, array ( 'primary' => true,)); - $this->hasColumn('sc_remark as remark', 'varchar', 500, array ()); - } - - public function setUp() - { - $this->hasOne('T626B_Student as Student', array('local' => 'sc_student_id', 'foreign' => 's_id')); - $this->hasOne('T626_Course as Course', array('local' => 'sc_course_id', 'foreign' => 'c_id')); + $class->setColumn('sc_student_id as student_id', 'varchar', 30, array ( 'primary' => true,)); + $class->setColumn('sc_course_id as course_id', 'varchar', 20, array ( 'primary' => true,)); + $class->setColumn('sc_remark as remark', 'varchar', 500, array ()); + $class->hasOne('T626B_Student as Student', array('local' => 'sc_student_id', 'foreign' => 's_id')); + $class->hasOne('T626_Course as Course', array('local' => 'sc_course_id', 'foreign' => 'c_id')); } } diff --git a/tests/Ticket/626CTestCase.php b/tests/Ticket/626CTestCase.php index 64f790a8c..4da2ec2e5 100644 --- a/tests/Ticket/626CTestCase.php +++ b/tests/Ticket/626CTestCase.php @@ -64,22 +64,22 @@ class Doctrine_Ticket_626C_TestCase extends Doctrine_UnitTestCase class T626C_Student1 extends Doctrine_Record { - public function setTableDefinition() + public static function initMetadata($class) { - $this->setTableName('T626C_Student_record_1'); + $class->setTableName('T626C_Student_record_1'); - $this->hasColumn('s_id as id', 'varchar', 30, array ( 'primary' => true,)); - $this->hasColumn('s_name as name', 'varchar', 50, array ()); + $class->setColumn('s_id as id', 'varchar', 30, array ( 'primary' => true,)); + $class->setColumn('s_name as name', 'varchar', 50, array ()); } } class T626C_Student2 extends Doctrine_Record { - public function setTableDefinition() + public static function initMetadata($class) { - $this->setTableName('T626C_Student_record_2'); + $class->setTableName('T626C_Student_record_2'); - $this->hasColumn('id', 'varchar', 30, array ( 'primary' => true,)); - $this->hasColumn('name', 'varchar', 50, array ()); + $class->setColumn('id', 'varchar', 30, array ( 'primary' => true,)); + $class->setColumn('name', 'varchar', 50, array ()); } } \ No newline at end of file diff --git a/tests/Ticket/626DTestCase.php b/tests/Ticket/626DTestCase.php index b2c50dd29..c950b3cbd 100644 --- a/tests/Ticket/626DTestCase.php +++ b/tests/Ticket/626DTestCase.php @@ -48,11 +48,11 @@ class Doctrine_Ticket_626D_TestCase extends Doctrine_UnitTestCase class T626D_Student1 extends Doctrine_Record { - public function setTableDefinition() + public static function initMetadata($class) { - $this->setTableName('T626D_Student_record_1'); + $class->setTableName('T626D_Student_record_1'); - $this->hasColumn('s_id as id', 'varchar', 30, array ( 'primary' => true,)); - $this->hasColumn('s_name as name', 'varchar', 50, array ()); + $class->setColumn('s_id as id', 'varchar', 30, array ( 'primary' => true,)); + $class->setColumn('s_name as name', 'varchar', 50, array ()); } } diff --git a/tests/Ticket/638TestCase.php b/tests/Ticket/638TestCase.php index d8e6988d7..f400291a2 100644 --- a/tests/Ticket/638TestCase.php +++ b/tests/Ticket/638TestCase.php @@ -107,32 +107,25 @@ class Doctrine_Ticket_638_TestCase extends Doctrine_UnitTestCase class T638_Student extends Doctrine_Record { - public function setTableDefinition() + public static function initMetadata($class) { - $this->setTableName('T638_student'); + $class->setTableName('T638_student'); - $this->hasColumn('s_id as id', 'varchar', 30, array ( 'primary' => true,)); - $this->hasColumn('s_g_id as group_id', 'varchar', 30, array ('notnull'=>true)); - $this->hasColumn('s_name as name', 'varchar', 50, array ('notnull'=>true)); + $class->setColumn('s_id as id', 'varchar', 30, array ( 'primary' => true,)); + $class->setColumn('s_g_id as group_id', 'varchar', 30, array ('notnull'=>true)); + $class->setColumn('s_name as name', 'varchar', 50, array ('notnull'=>true)); } - public function setUp() - { - } } class T638_Course extends Doctrine_Record { - public function setTableDefinition() + public static function initMetadata($class) { - $this->setTableName('T638_course'); + $class->setTableName('T638_course'); - $this->hasColumn('c_id as id', 'varchar', 20, array ( 'primary' => true,)); - $this->hasColumn('c_name as name', 'varchar', 50, array ('notnull'=>true)); - } - - public function setUp() - { + $class->setColumn('c_id as id', 'varchar', 20, array ( 'primary' => true,)); + $class->setColumn('c_name as name', 'varchar', 50, array ('notnull'=>true)); } public function set($fieldName, $value, $load = true) @@ -143,19 +136,16 @@ class T638_Course extends Doctrine_Record class T638_StudentCourse extends Doctrine_Record { - public function setTableDefinition() + public static function initMetadata($class) { - $this->setTableName('T638_Student_course'); + $class->setTableName('T638_Student_course'); - $this->hasColumn('sc_student_id as student_id', 'varchar', 30, array ( 'primary' => true,)); - $this->hasColumn('sc_course_id as course_id', 'varchar', 20, array ( 'primary' => true,)); - $this->hasColumn('sc_remark as remark', 'varchar', 500, array ('notnull'=>true)); - } - - public function setUp() - { - $this->hasOne('T638_Student as Student', array('local' => 'sc_student_id', 'foreign' => 's_id')); - $this->hasOne('T638_Course as Course', array('local' => 'sc_course_id', 'foreign' => 'c_id')); + $class->setColumn('sc_student_id as student_id', 'varchar', 30, array ( 'primary' => true,)); + $class->setColumn('sc_course_id as course_id', 'varchar', 20, array ( 'primary' => true,)); + $class->setColumn('sc_remark as remark', 'varchar', 500, array ('notnull'=>true)); + + $class->hasOne('T638_Student as Student', array('local' => 'sc_student_id', 'foreign' => 's_id')); + $class->hasOne('T638_Course as Course', array('local' => 'sc_course_id', 'foreign' => 'c_id')); } } diff --git a/tests/Ticket/642TestCase.php b/tests/Ticket/642TestCase.php index a5d7dffe7..93cab5902 100644 --- a/tests/Ticket/642TestCase.php +++ b/tests/Ticket/642TestCase.php @@ -52,10 +52,10 @@ class Doctrine_Ticket_642_TestCase extends Doctrine_UnitTestCase class stDummyObj extends Doctrine_Record { - public function setTableDefinition() + public static function initMetadata($class) { - $this->setTableName('st_dummy_obj'); - $this->hasColumn('startDate', 'timestamp', null, array( + $class->setTableName('st_dummy_obj'); + $class->setColumn('startDate', 'timestamp', null, array( 'notnull' => true, 'default' => '0000-00-00 00:00:00' )); diff --git a/tests/Ticket/673TestCase.php b/tests/Ticket/673TestCase.php index a1ae277c9..681fdd485 100644 --- a/tests/Ticket/673TestCase.php +++ b/tests/Ticket/673TestCase.php @@ -60,12 +60,12 @@ class Doctrine_Ticket_673_TestCase extends Doctrine_UnitTestCase class T673_Student extends Doctrine_Record { - public function setTableDefinition() + public static function initMetadata($class) { - $this->setTableName('T673_Student_record'); + $class->setTableName('T673_Student_record'); - $this->hasColumn('s_id as id', 'varchar', 30, array ( 'primary' => true,)); - $this->hasColumn('s_foo as foo', 'integer', 4, array ('notnull'=>true)); - $this->hasColumn('s_name as name', 'varchar', 50, array ()); + $class->setColumn('s_id as id', 'varchar', 30, array ( 'primary' => true,)); + $class->setColumn('s_foo as foo', 'integer', 4, array ('notnull'=>true)); + $class->setColumn('s_name as name', 'varchar', 50, array ()); } } diff --git a/tests/Ticket/697TestCase.php b/tests/Ticket/697TestCase.php index f6ae4ed2e..5a514c2fd 100644 --- a/tests/Ticket/697TestCase.php +++ b/tests/Ticket/697TestCase.php @@ -22,11 +22,7 @@ class Doctrine_Ticket_697_TestCase extends Doctrine_UnitTestCase } public function testIdsAreSetWhenSavingSubclassInstancesInCTI() - { - $personTable = $this->conn->getTable('T697_Person'); - $userTable = $this->conn->getTable('T697_User'); - //var_dump($userTable->getColumns()); - + { $p = new T697_Person(); $p['name']='Rodrigo'; $p->save(); @@ -42,21 +38,26 @@ class Doctrine_Ticket_697_TestCase extends Doctrine_UnitTestCase class T697_Person extends Doctrine_Record { - public function setTableDefinition() + public static function initMetadata($class) { - $this->setInheritanceType(Doctrine::INHERITANCETYPE_JOINED, - array('T697_Person' => array('dtype' => 1), 'T697_User' => array('dtype' => 2))); - $this->setTableName('t697_person'); - $this->hasColumn('name', 'string', 30); - $this->hasColumn('dtype', 'integer', 4); + $class->setInheritanceType(Doctrine::INHERITANCETYPE_JOINED, array( + 'discriminatorColumn' => 'dtype', + 'discriminatorMap' => array( + 1 => 'T697_Person', 2 => 'T697_User' + ) + )); + $class->setSubclasses(array('T697_User')); + $class->setTableName('t697_person'); + $class->setColumn('name', 'string', 30); + $class->setColumn('dtype', 'integer', 4); } } //Class table inheritance class T697_User extends T697_Person { - public function setTableDefinition() + public static function initMetadata($class) { - $this->setTableName('t697_user'); - $this->hasColumn('password', 'string', 30); + $class->setTableName('t697_user'); + $class->setColumn('password', 'string', 30); } } diff --git a/tests/Ticket/741TestCase.php b/tests/Ticket/741TestCase.php index 2e0047094..c265e651f 100644 --- a/tests/Ticket/741TestCase.php +++ b/tests/Ticket/741TestCase.php @@ -31,39 +31,31 @@ class Doctrine_Ticket_741_TestCase extends Doctrine_UnitTestCase class Parent741 extends Doctrine_Record { - public function setTableDefinition() + public static function initMetadata($class) { - $this->hasColumn('id', 'integer', 4, array ( + $class->setColumn('id', 'integer', 4, array ( 'primary' => true, 'autoincrement' => true, 'notnull' => true, )); - $this->hasColumn('amount', 'integer'); - } - - public function setUp() - { - $this->hasMany('Child741 as Cows', array('local' => 'id', 'foreign' => 'moo_id')); + $class->setColumn('amount', 'integer'); + $class->hasMany('Child741 as Cows', array('local' => 'id', 'foreign' => 'moo_id')); } } class Child741 extends Doctrine_Record { - public function setTableDefinition() + public static function initMetadata($class) { - $this->hasColumn('id', 'integer', 4, array ( + $class->setColumn('id', 'integer', 4, array ( 'primary' => true, 'autoincrement' => true, 'notnull' => true, )); - $this->hasColumn('moo_id', 'integer'); - } - - public function setUp() - { - $this->hasOne('Parent741 as Moo', array('local' => 'moo_id', 'foreign' => 'id')); + $class->setColumn('moo_id', 'integer'); + $class->hasOne('Parent741 as Moo', array('local' => 'moo_id', 'foreign' => 'id')); } public function postInsert($e) @@ -86,5 +78,3 @@ class Child741 extends Doctrine_Record */ } } - - diff --git a/tests/Ticket/NjeroTestCase.php b/tests/Ticket/NjeroTestCase.php index ea4f64bb1..c32137140 100644 --- a/tests/Ticket/NjeroTestCase.php +++ b/tests/Ticket/NjeroTestCase.php @@ -16,6 +16,7 @@ class Doctrine_Ticket_Njero_TestCase extends Doctrine_UnitTestCase public function prepareData() { } public function prepareTables() { + $this->tables = array(); $this->tables[] = 'CoverageCodeN'; $this->tables[] = 'PolicyCodeN'; $this->tables[] = 'LiabilityCodeN'; diff --git a/tests/run.php b/tests/run.php index ffc5471ee..e2ac69022 100644 --- a/tests/run.php +++ b/tests/run.php @@ -157,12 +157,12 @@ $plugins = new GroupTest('Plugin tests: View, Validator, Hook', 'plugins'); //$plugins->addTestCase(new Doctrine_PessimisticLocking_TestCase()); //$plugins->addTestCase(new Doctrine_Plugin_TestCase()); $plugins->addTestCase(new Doctrine_View_TestCase()); -$plugins->addTestCase(new Doctrine_AuditLog_TestCase()); +//$plugins->addTestCase(new Doctrine_AuditLog_TestCase()); $plugins->addTestCase(new Doctrine_Validator_TestCase()); $plugins->addTestCase(new Doctrine_Validator_Future_TestCase()); $plugins->addTestCase(new Doctrine_Validator_Past_TestCase()); $plugins->addTestCase(new Doctrine_Hook_TestCase()); -$plugins->addTestCase(new Doctrine_I18n_TestCase()); +//$plugins->addTestCase(new Doctrine_I18n_TestCase()); $test->addTestCase($plugins); // Db component @@ -179,10 +179,21 @@ $test->addTestCase($event_listener); // Query tests $query_tests = new GroupTest('Query tests','query_test'); +## The following tests seem to influence each other when the whole suite is run... +$query_tests->addTestCase(new Doctrine_Query_JoinCondition2_TestCase()); +$query_tests->addTestCase(new Doctrine_Query_Select_TestCase()); +$query_tests->addTestCase(new Doctrine_Query_MultipleAggregateValue_TestCase()); +$query_tests->addTestCase(new Doctrine_Query_AggregateValue_TestCase()); +## + +# Passes with filter=query or filter=query_referencemodel but fail when running the +# whole suite ... +$query_tests->addTestCase(new Doctrine_Query_ReferenceModel_TestCase()); +# + $query_tests->addTestCase(new Doctrine_Query_Condition_TestCase()); $query_tests->addTestCase(new Doctrine_Query_MultiJoin_TestCase()); $query_tests->addTestCase(new Doctrine_Query_MultiJoin2_TestCase()); -$query_tests->addTestCase(new Doctrine_Query_ReferenceModel_TestCase()); $query_tests->addTestCase(new Doctrine_Query_ComponentAlias_TestCase()); $query_tests->addTestCase(new Doctrine_Query_ShortAliases_TestCase()); $query_tests->addTestCase(new Doctrine_Query_Expression_TestCase()); @@ -198,13 +209,9 @@ $query_tests->addTestCase(new Doctrine_Query_Orderby_TestCase()); $query_tests->addTestCase(new Doctrine_Query_Subquery_TestCase()); $query_tests->addTestCase(new Doctrine_Query_Driver_TestCase()); $query_tests->addTestCase(new Doctrine_Record_Hook_TestCase()); -$query_tests->addTestCase(new Doctrine_Query_AggregateValue_TestCase()); $query_tests->addTestCase(new Doctrine_Query_Where_TestCase()); $query_tests->addTestCase(new Doctrine_Query_From_TestCase()); -$query_tests->addTestCase(new Doctrine_Query_Select_TestCase()); $query_tests->addTestCase(new Doctrine_Query_JoinCondition_TestCase()); -$query_tests->addTestCase(new Doctrine_Query_JoinCondition2_TestCase()); -$query_tests->addTestCase(new Doctrine_Query_MultipleAggregateValue_TestCase()); $query_tests->addTestCase(new Doctrine_Query_TestCase()); $query_tests->addTestCase(new Doctrine_Query_MysqlSubquery_TestCase()); $query_tests->addTestCase(new Doctrine_Query_PgsqlSubquery_TestCase()); @@ -239,7 +246,7 @@ $test->addTestCase(new Doctrine_RawSql_TestCase()); $test->addTestCase(new Doctrine_NewCore_TestCase()); -$test->addTestCase(new Doctrine_Template_TestCase()); +//$test->addTestCase(new Doctrine_Template_TestCase()); //$test->addTestCase(new Doctrine_Import_Builder_TestCase()); @@ -248,6 +255,9 @@ $test->addTestCase(new Doctrine_Inheritance_SingleTable_TestCase()); $test->addTestCase(new Doctrine_Inheritance_Joined_TestCase()); $test->addTestCase(new Doctrine_Inheritance_TablePerClass_TestCase()); +// Metadata loading tests +$test->addTestCase(new Doctrine_Metadata_Factory_TestCase()); + // nestedset tests $test->addTestCase(new Doctrine_NestedSet_SingleRoot_TestCase()); $test->addTestCase(new Doctrine_NestedSet_LoadInSetUp_TestCase()); @@ -274,7 +284,7 @@ $test->addTestCase($cache); // Migration Tests $migration = new GroupTest('Migration tests','migration'); -$migration->addTestCase(new Doctrine_Migration_TestCase()); +//$migration->addTestCase(new Doctrine_Migration_TestCase()); //$migration->addTestCase(new Doctrine_Migration_Mysql_TestCase()); $test->addTestCase($migration);