/** * Add a new table object to the database. * * @param \Propel\Runtime\Map\TableMap $table The table to add */ public function addTableObject(TableMap $table) { $table->setDatabaseMap($this); $this->tables[$table->getName()] = $table; $phpName = $table->getClassName(); if ('\\' !== $phpName[0]) { $phpName = '\\' . $phpName; } $this->tablesByPhpName[$phpName] = $table; }
/** * Maps options like limit, offset, order * * @param ModelCriteria $query * @param array $options * * @throws FileNotFoundException */ public function mapOptions(ModelCriteria $query, $options = array()) { if (isset($options['limit'])) { $query->limit($options['limit']); } if (isset($options['offset'])) { $query->offset($options['offset']); } if (isset($options['order']) && is_array($options['order'])) { foreach ($options['order'] as $field => $direction) { $fieldName = ucfirst($field); $tableMap = $this->tableMap; if (false !== ($pos = strpos($field, '.'))) { $relationName = ucfirst(substr($field, 0, $pos)); $fieldName = ucfirst(substr($field, $pos + 1)); if (!($relation = $this->tableMap->getRelation($relationName))) { throw new FileNotFoundException(sprintf('Relation `%s` in object `%s` not found', $relationName, $this->getObjectKey())); } $tableMap = $relation->getForeignTable(); } if ($tableMap->hasColumnByPhpName(ucfirst($fieldName))) { $column = $this->tableMap->getColumnByPhpName(ucfirst($fieldName)); $query->orderBy($column->getName(), $direction); } } } }
/** * Sets the alias for the model in this query * * @param string $modelAlias The model alias * @param boolean $useAliasInSQL Whether to use the alias in the SQL code (false by default) * * @return $this|ModelCriteria The current object, for fluid interface */ public function setModelAlias($modelAlias, $useAliasInSQL = false) { if ($useAliasInSQL) { $this->addAlias($modelAlias, $this->tableMap->getName()); $this->useAliasInSQL = true; } $this->modelAlias = $modelAlias; return $this; }
/** * Method from the TableMap API */ public function getRelations() { // table maps $authorTable = new TableMap(); $authorTable->setClassName('\\Foo\\Author'); $resellerTable = new TableMap(); $resellerTable->setClassName('\\Foo\\Reseller'); // relations $mainAuthorRelation = new RelationMap('MainAuthor'); $mainAuthorRelation->setType(RelationMap::MANY_TO_ONE); $mainAuthorRelation->setForeignTable($authorTable); $authorRelation = new RelationMap('Author'); $authorRelation->setType(RelationMap::ONE_TO_MANY); $authorRelation->setForeignTable($authorTable); $resellerRelation = new RelationMap('Reseller'); $resellerRelation->setType(RelationMap::MANY_TO_MANY); $resellerRelation->setLocalTable($resellerTable); return array($mainAuthorRelation, $authorRelation, $resellerRelation); }
public function testColumns() { $this->assertEquals(array(), $this->rmap->getLocalColumns(), 'A new relation has no local columns'); $this->assertEquals(array(), $this->rmap->getForeignColumns(), 'A new relation has no foreign columns'); $tmap1 = new TableMap('foo', $this->databaseMap); $col1 = $tmap1->addColumn('FOO1', 'Foo1PhpName', 'INTEGER'); $tmap2 = new TableMap('bar', $this->databaseMap); $col2 = $tmap2->addColumn('BAR1', 'Bar1PhpName', 'INTEGER'); $this->rmap->addColumnMapping($col1, $col2); $this->assertEquals(array($col1), $this->rmap->getLocalColumns(), 'addColumnMapping() adds a local table'); $this->assertEquals(array($col2), $this->rmap->getForeignColumns(), 'addColumnMapping() adds a foreign table'); $expected = array('foo.FOO1' => 'bar.BAR1'); $this->assertEquals($expected, $this->rmap->getColumnMappings(), 'getColumnMappings() returns an associative array of column mappings'); $col3 = $tmap1->addColumn('FOOFOO', 'FooFooPhpName', 'INTEGER'); $col4 = $tmap2->addColumn('BARBAR', 'BarBarPhpName', 'INTEGER'); $this->rmap->addColumnMapping($col3, $col4); $this->assertEquals(array($col1, $col3), $this->rmap->getLocalColumns(), 'addColumnMapping() adds a local table'); $this->assertEquals(array($col2, $col4), $this->rmap->getForeignColumns(), 'addColumnMapping() adds a foreign table'); $expected = array('foo.FOO1' => 'bar.BAR1', 'foo.FOOFOO' => 'bar.BARBAR'); $this->assertEquals($expected, $this->rmap->getColumnMappings(), 'getColumnMappings() returns an associative array of column mappings'); }
public function removePrefix($data) { return parent::removePrefix($data); }
public function normalizeColName($name) { return parent::normalizeColName($name); }
/** * Tests the BaseTableMap::translateFieldName() method */ public function testTranslateFieldNameStatic() { $types = array(TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM); $expecteds = array(TableMap::TYPE_PHPNAME => 'AuthorId', TableMap::TYPE_STUDLYPHPNAME => 'authorId', TableMap::TYPE_COLNAME => 'book.AUTHOR_ID', TableMap::TYPE_FIELDNAME => 'author_id', TableMap::TYPE_NUM => 5); foreach ($types as $fromType) { foreach ($types as $toType) { $name = $expecteds[$fromType]; $expected = $expecteds[$toType]; $result = TableMap::translateFieldNameForClass('\\Propel\\Tests\\Bookstore\\Book', $name, $fromType, $toType); $this->assertEquals($expected, $result); } } }
/** * Add a new table object to the database. * * @param \Propel\Runtime\Map\TableMap $table The table to add */ public function addTableObject(TableMap $table) { $table->setDatabaseMap($this); $this->tables[$table->getName()] = $table; $this->tablesByPhpName[$table->getClassname()] = $table; }
/** * @param string $value values with starting ':' mean a column name, otherwise a regular value. * @param TableMap $table * * @return ColumnMap|mixed */ protected function getColumnOrValue($value, TableMap $table) { if (':' === substr($value, 0, 1)) { return $table->getColumn(substr($value, 1)); } else { return $value; } }
public function testGetTableByPhpName() { try { $this->databaseMap->getTableByPhpName('Foo1'); $this->fail('getTableByPhpName() throws an exception when called on an inexistent table'); } catch (TableNotFoundException $e) { $this->assertTrue(true, 'getTableByPhpName() throws an exception when called on an inexistent table'); } $tmap = $this->databaseMap->addTable('foo1'); try { $this->databaseMap->getTableByPhpName('Foo1'); $this->fail('getTableByPhpName() throws an exception when called on a table with no phpName'); } catch (TableNotFoundException $e) { $this->assertTrue(true, 'getTableByPhpName() throws an exception when called on a table with no phpName'); } $tmap2 = new TableMap('foo2'); $tmap2->setClassname('Foo2'); $this->databaseMap->addTableObject($tmap2); $this->assertEquals($tmap2, $this->databaseMap->getTableByPhpName('Foo2'), 'getTableByPhpName() returns tableMap when phpName was set by way of TableMap::setPhpName()'); }