Changeset 7147
- Timestamp:
- 01/22/08 12:11:01 (10 months ago)
- Files:
-
- branches/1.1/lib/plugins/sfPropelPlugin/data/generator/sfPropelForm/default/template/sfPropelFormGeneratedTemplate.php (modified) (5 diffs)
- branches/1.1/lib/plugins/sfPropelPlugin/lib/propel/generator/sfPropelFormGenerator.class.php (modified) (4 diffs)
- branches/1.1/lib/plugins/sfPropelPlugin/lib/propel/validator/sfValidatorPropelChoice.class.php (added)
- branches/1.1/lib/plugins/sfPropelPlugin/lib/propel/validator/sfValidatorPropelChoiceMany.class.php (added)
- branches/1.1/lib/plugins/sfPropelPlugin/lib/propel/widget (added)
- branches/1.1/lib/plugins/sfPropelPlugin/lib/propel/widget/sfWidgetFormPropelSelect.class.php (added)
- branches/1.1/lib/plugins/sfPropelPlugin/lib/propel/widget/sfWidgetFormPropelSelectMany.class.php (added)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/crud/crudBrowser.class.php (modified) (7 diffs)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/config/schema.xml (modified) (1 diff)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/data/sql/lib.model.schema.sql (modified) (2 diffs)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/base/BaseArticleForm.class.php (modified) (3 diffs)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/base/BaseAuthorArticleForm.class.php (modified) (2 diffs)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/base/BaseAuthorForm.class.php (modified) (2 diffs)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/base/BaseBookForm.class.php (modified) (1 diff)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/base/BaseCategoryForm.class.php (modified) (1 diff)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/model/Author.php (modified) (1 diff)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/model/map/AuthorArticleMapBuilder.php (modified) (1 diff)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/model/om/BaseAuthorArticle.php (modified) (13 diffs)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/model/om/BaseAuthorArticlePeer.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.1/lib/plugins/sfPropelPlugin/data/generator/sfPropelForm/default/template/sfPropelFormGeneratedTemplate.php
r7055 r7147 18 18 <?php endforeach; ?> 19 19 <?php foreach ($this->getManyToManyTables() as $tables): ?> 20 '<?php echo $tables['relatedTable']->getName() ?>_list'<?php echo str_repeat(' ', $this->getColumnNameMaxLength() - strlen($tables['relatedTable']->getName().'_list')) ?> => new sfWidgetForm SelectMany(array('choices' => new sfCallable(array($this, 'get<?php echo $tables['middleTable']->getPhpName() ?>Choices')))),20 '<?php echo $tables['relatedTable']->getName() ?>_list'<?php echo str_repeat(' ', $this->getColumnNameMaxLength() - strlen($tables['relatedTable']->getName().'_list')) ?> => new sfWidgetFormPropelSelectMany(array('model' => '<?php echo $tables['relatedTable']->getPhpName() ?>')), 21 21 <?php endforeach; ?> 22 22 )); … … 27 27 <?php endforeach; ?> 28 28 <?php foreach ($this->getManyToManyTables() as $tables): ?> 29 '<?php echo $tables['relatedTable']->getName() ?>_list'<?php echo str_repeat(' ', $this->getColumnNameMaxLength() - strlen($tables['relatedTable']->getName().'_list')) ?> => new sfValidator ChoiceMany(array('choices' => new sfCallable(array($this, 'get<?php echo $tables['middleTable']->getPhpName() ?>IdentifierChoices')), 'required' => false)),29 '<?php echo $tables['relatedTable']->getName() ?>_list'<?php echo str_repeat(' ', $this->getColumnNameMaxLength() - strlen($tables['relatedTable']->getName().'_list')) ?> => new sfValidatorPropelChoiceMany(array('model' => '<?php echo $tables['relatedTable']->getPhpName() ?>', 'required' => false)), 30 30 <?php endforeach; ?> 31 31 )); … … 55 55 <?php endif; ?> 56 56 57 <?php foreach ($this->getForeignKeyNames() as $info): $name = $info[1] ?>58 public function get<?php echo $name ?>IdentifierChoices()59 {60 return array_keys($this->get<?php echo $name ?>Choices());61 }62 63 public function get<?php echo $name ?>Choices()64 {65 if (!isset($this-><?php echo $name ?>Choices))66 {67 $this-><?php echo $name ?>Choices = array(<?php !$info[2] && !$info[3] and print "'' => ''" ?>);68 foreach (<?php echo $info[0] ?>Peer::doSelect(new Criteria(), $this->getConnection()) as $object)69 {70 $this-><?php echo $name ?>Choices[$object->get<?php echo $this->getPrimaryKey()->getPhpName() ?>()] = $object->__toString();71 }72 }73 74 return $this-><?php echo $name ?>Choices;75 }76 <?php endforeach; ?>77 78 57 <?php if ($this->getManyToManyTables()): ?> 79 58 public function updateDefaultsFromObject() … … 92 71 $this->setDefault('<?php echo $tables['relatedTable']->getName() ?>_list', $values); 93 72 } 73 94 74 <?php endforeach; ?> 95 75 } … … 139 119 } 140 120 } 121 141 122 <?php endforeach; ?> 142 123 <?php endif; ?> branches/1.1/lib/plugins/sfPropelPlugin/lib/propel/generator/sfPropelFormGenerator.class.php
r7055 r7147 226 226 else if ($column->isForeignKey()) 227 227 { 228 $name = ' Select';228 $name = 'PropelSelect'; 229 229 } 230 230 … … 245 245 if (!$column->isPrimaryKey() && $column->isForeignKey()) 246 246 { 247 $options[] = sprintf('\' choices\' => new sfCallable(array($this, \'get%sChoices\'))', $column->getPhpName());247 $options[] = sprintf('\'model\' => \'%s\', \'add_empty\' => %s', $this->getForeignTable($column)->getPhpName(), $column->isNotNull() ? 'false' : 'true'); 248 248 } 249 249 … … 299 299 if (!$column->isPrimaryKey() && $column->isForeignKey()) 300 300 { 301 $name = ' Choice';301 $name = 'PropelChoice'; 302 302 } 303 303 … … 331 331 if (!$column->isPrimaryKey() && $column->isForeignKey()) 332 332 { 333 $options[] = sprintf('\' choices\' => new sfCallable(array($this, \'get%sIdentifierChoices\'))', $column->getPhpName());333 $options[] = sprintf('\'model\' => \'%s\'', $this->getForeignTable($column)->getPhpName()); 334 334 } 335 335 branches/1.1/lib/plugins/sfPropelPlugin/test/functional/crud/crudBrowser.class.php
r6950 r7147 94 94 'end_date' => array('year' => '', 'month' => '', 'day' => '', 'hour' => '', 'minute' => ''), 95 95 'book_id' => 0, 96 'author_list' => array(), 96 97 )) 97 98 ; … … 106 107 'end_date' => array('year' => '', 'month' => '', 'day' => '', 'hour' => '', 'minute' => ''), 107 108 'book_id' => null, 109 'author_list' => array(1, 2), 108 110 ), 3); 109 111 … … 139 141 checkResponseElement('table tbody th:nth(5)', 'End date')-> 140 142 checkResponseElement('table tbody th:nth(6)', 'Book id')-> 141 checkResponseElement('table tbody th', 7)-> 142 143 checkResponseElement('table tbody td', 7)-> 143 checkResponseElement('table tbody th:nth(7)', 'Author list')-> 144 checkResponseElement('table tbody th', 8)-> 145 146 checkResponseElement('table tbody td', 8)-> 144 147 checkResponseElement('table tbody td select[id="article_category_id"][name="article[category_id]"] option', 2)-> 145 148 checkResponseElement('table tbody td select[id="article_book_id"][name="article[book_id]"] option', 2) … … 155 158 'end_date' => array('year' => 0, 'month' => 0, 'day' => 15, 'hour' => '10', 'minute' => '20'), 156 159 'book_id' => 14, 160 'author_list' => array(0, 5), 157 161 ); 158 162 $this-> … … 165 169 )-> 166 170 checkResponseElement('ul[class="error_list"] li:contains("Required.")', 2)-> 167 checkResponseElement('ul[class="error_list"] li:contains("Invalid.")', 2)171 checkResponseElement('ul[class="error_list"] li:contains("Invalid.")', 3) 168 172 ; 169 173 … … 177 181 'end_date' => array('year' => 2005, 'month' => 10, 'day' => 15, 'hour' => '10', 'minute' => '20'), 178 182 'book_id' => 1, 183 'author_list' => array(1, 3), 179 184 ), 3); 180 185 … … 278 283 checkResponseElement(sprintf('table tbody td select[id="article_book_id"][name="article[book_id]"] option[value="1"]%s', $values['book_id'] == 1 ? '[selected="selected"]' : ''), 'The definitive guide to symfony')-> 279 284 285 checkResponseElement(sprintf('table tbody td select[id="article_author_list"][name="article[author_list][]"] option[value="1"]%s', in_array(1, $values['author_list']) ? '[selected="selected"]' : ''), 'Fabien')-> 286 checkResponseElement(sprintf('table tbody td select[id="article_author_list"][name="article[author_list][]"] option[value="2"]%s', in_array(2, $values['author_list']) ? '[selected="selected"]' : ''), 'Thomas')-> 287 checkResponseElement(sprintf('table tbody td select[id="article_author_list"][name="article[author_list][]"] option[value="3"]%s', in_array(3, $values['author_list']) ? '[selected="selected"]' : ''), 'Hélène')-> 288 280 289 checkResponseElement('table tbody td select[id="article_end_date_year"][name="article[end_date][year]"] option[selected="selected"]', (string) $values['end_date']['year'])-> 281 290 checkResponseElement('table tbody td select[id="article_end_date_month"][name="article[end_date][month]"] option[selected="selected"]', (string) $values['end_date']['month'])-> branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/config/schema.xml
r6882 r7147 35 35 36 36 <table name="author_article"> 37 <column name="author_id" type="integer" />37 <column name="author_id" type="integer" primaryKey="true" /> 38 38 <foreign-key foreignTable="author"> 39 39 <reference local="author_id" foreign="id" /> 40 40 </foreign-key> 41 <column name="article_id" type="integer" />41 <column name="article_id" type="integer" primaryKey="true" /> 42 42 <foreign-key foreignTable="article"> 43 43 <reference local="article_id" foreign="id" /> 44 44 </foreign-key> 45 <column name="id" type="integer" required="true" primaryKey="true" autoincrement="true" />46 45 </table> 47 46 branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/data/sql/lib.model.schema.sql
r5103 r7147 10 10 ( 11 11 [id] INTEGER NOT NULL PRIMARY KEY, 12 [title] VARCHAR(255) ,12 [title] VARCHAR(255) NOT NULL, 13 13 [body] MEDIUMTEXT, 14 14 [online] INTEGER, … … 73 73 CREATE TABLE [author_article] 74 74 ( 75 [author_id] INTEGER, 76 [article_id] INTEGER, 77 [id] INTEGER NOT NULL PRIMARY KEY 75 [author_id] INTEGER NOT NULL, 76 [article_id] INTEGER NOT NULL 78 77 ); 79 78 branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/base/BaseArticleForm.class.php
r6944 r7147 17 17 'body' => new sfWidgetFormTextarea(), 18 18 'online' => new sfWidgetFormInputCheckbox(), 19 'category_id' => new sfWidgetForm Select(array('choices' => new sfCallable(array($this, 'getCategoryChoices')))),19 'category_id' => new sfWidgetFormPropelSelect(array('model' => 'Category', 'add_empty' => false)), 20 20 'created_at' => new sfWidgetFormDateTime(), 21 21 'end_date' => new sfWidgetFormDateTime(), 22 'book_id' => new sfWidgetFormSelect(array('choices' => new sfCallable(array($this, 'getBookChoices')))), 22 'book_id' => new sfWidgetFormPropelSelect(array('model' => 'Book', 'add_empty' => true)), 23 'author_list' => new sfWidgetFormPropelSelectMany(array('model' => 'Author')), 23 24 )); 24 25 … … 28 29 'body' => new sfValidatorString(array('required' => false)), 29 30 'online' => new sfValidatorBoolean(array('required' => false)), 30 'category_id' => new sfValidator Choice(array('choices' => new sfCallable(array($this, 'getCategoryIdentifierChoices')))),31 'category_id' => new sfValidatorPropelChoice(array('model' => 'Category')), 31 32 'created_at' => new sfValidatorDateTime(array('required' => false)), 32 33 'end_date' => new sfValidatorDateTime(array('required' => false)), 33 'book_id' => new sfValidatorChoice(array('choices' => new sfCallable(array($this, 'getBookIdentifierChoices')), 'required' => false)), 34 'book_id' => new sfValidatorPropelChoice(array('model' => 'Book', 'required' => false)), 35 'author_list' => new sfValidatorPropelChoiceMany(array('model' => 'Author', 'required' => false)), 34 36 )); 35 37 … … 47 49 48 50 49 public function getCategoryIdentifierChoices()51 public function updateDefaultsFromObject() 50 52 { 51 return array_keys($this->getCategoryChoices()); 53 parent::updateDefaultsFromObject(); 54 55 if (isset($this->widgetSchema['author_list'])) 56 { 57 $values = array(); 58 foreach ($this->object->getAuthorArticles() as $obj) 59 { 60 $values[] = $obj->getAuthorId(); 61 } 62 63 $this->setDefault('author_list', $values); 64 } 65 52 66 } 53 67 54 p ublic function getCategoryChoices()68 protected function doSave($con = null) 55 69 { 56 if (!isset($this->CategoryChoices)) 70 parent::doSave($con); 71 72 $this->saveAuthorList($con); 73 } 74 75 public function saveAuthorList($con = null) 76 { 77 if (!$this->isValid()) 57 78 { 58 $this->CategoryChoices = array(); 59 foreach (CategoryPeer::doSelect(new Criteria(), $this->getConnection()) as $object) 79 throw $this->getErrorSchema(); 80 } 81 82 if (!isset($this->widgetSchema['author_list'])) 83 { 84 // somebody has unset this widget 85 return; 86 } 87 88 if (is_null($con)) 89 { 90 $con = $this->getConnection(); 91 } 92 93 $c = new Criteria(); 94 $c->add(AuthorArticlePeer::ARTICLE_ID, $this->object->getPrimaryKey()); 95 AuthorArticlePeer::doDelete($c, $con); 96 97 $values = $this->getValues(); 98 if (is_array($values['author_list'])) 99 { 100 foreach ($values['author_list'] as $value) 60 101 { 61 $this->CategoryChoices[$object->getId()] = $object->__toString(); 102 $obj = new AuthorArticle(); 103 $obj->setArticleId($this->object->getPrimaryKey()); 104 $obj->setAuthorId($value); 105 $obj->save(); 62 106 } 63 107 } 64 65 return $this->CategoryChoices;66 }67 public function getBookIdentifierChoices()68 {69 return array_keys($this->getBookChoices());70 }71 72 public function getBookChoices()73 {74 if (!isset($this->BookChoices))75 {76 $this->BookChoices = array('' => '');77 foreach (BookPeer::doSelect(new Criteria(), $this->getConnection()) as $object)78 {79 $this->BookChoices[$object->getId()] = $object->__toString();80 }81 }82 83 return $this->BookChoices;84 108 } 85 109 branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/base/BaseAuthorArticleForm.class.php
r6944 r7147 13 13 { 14 14 $this->setWidgets(array( 15 'author_id' => new sfWidgetFormSelect(array('choices' => new sfCallable(array($this, 'getAuthorChoices')))), 16 'article_id' => new sfWidgetFormSelect(array('choices' => new sfCallable(array($this, 'getArticleChoices')))), 17 'id' => new sfWidgetFormInputHidden(), 15 'author_id' => new sfWidgetFormInputHidden(), 16 'article_id' => new sfWidgetFormInputHidden(), 18 17 )); 19 18 20 19 $this->setValidators(array( 21 'author_id' => new sfValidatorChoice(array('choices' => new sfCallable(array($this, 'getAuthorIdentifierChoices')), 'required' => false)), 22 'article_id' => new sfValidatorChoice(array('choices' => new sfCallable(array($this, 'getArticleIdentifierChoices')), 'required' => false)), 23 'id' => new sfValidatorInteger(array('required' => false)), 20 'author_id' => new sfValidatorInteger(array('required' => false)), 21 'article_id' => new sfValidatorInteger(array('required' => false)), 24 22 )); 25 23 … … 37 35 38 36 39 public function getAuthorIdentifierChoices()40 {41 return array_keys($this->getAuthorChoices());42 }43 44 public function getAuthorChoices()45 {46 if (!isset($this->AuthorChoices))47 {48 $this->AuthorChoices = array('' => '');49 foreach (AuthorPeer::doSelect(new Criteria(), $this->getConnection()) as $object)50 {51 $this->AuthorChoices[$object->getId()] = $object->__toString();52 }53 }54 55 return $this->AuthorChoices;56 }57 public function getArticleIdentifierChoices()58 {59 return array_keys($this->getArticleChoices());60 }61 62 public function getArticleChoices()63 {64 if (!isset($this->ArticleChoices))65 {66 $this->ArticleChoices = array('' => '');67 foreach (ArticlePeer::doSelect(new Criteria(), $this->getConnection()) as $object)68 {69 $this->ArticleChoices[$object->getId()] = $object->__toString();70 }71 }72 73 return $this->ArticleChoices;74 }75 76 37 } branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/base/BaseAuthorForm.class.php
r6944 r7147 13 13 { 14 14 $this->setWidgets(array( 15 'id' => new sfWidgetFormInputHidden(), 16 'name' => new sfWidgetFormInput(), 15 'id' => new sfWidgetFormInputHidden(), 16 'name' => new sfWidgetFormInput(), 17 'article_list' => new sfWidgetFormPropelSelectMany(array('model' => 'Article')), 17 18 )); 18 19 19 20 $this->setValidators(array( 20 'id' => new sfValidatorInteger(array('required' => false)), 21 'name' => new sfValidatorString(array('required' => false)), 21 'id' => new sfValidatorInteger(array('required' => false)), 22 'name' => new sfValidatorString(array('required' => false)), 23 'article_list' => new sfValidatorPropelChoiceMany(array('model' => 'Article', 'required' => false)), 22 24 )); 23 25 … … 35 37 36 38 39 public function updateDefaultsFromObject() 40 { 41 parent::updateDefaultsFromObject(); 42 43 if (isset($this->widgetSchema['article_list'])) 44 { 45 $values = array(); 46 foreach ($this->object->getAuthorArticles() as $obj) 47 { 48 $values[] = $obj->getArticleId(); 49 } 50 51 $this->setDefault('article_list', $values); 52 } 53 54 } 55 56 protected function doSave($con = null) 57 { 58 parent::doSave($con); 59 60 $this->saveArticleList($con); 61 } 62 63 public function saveArticleList($con = null) 64 { 65 if (!$this->isValid()) 66 { 67 throw $this->getErrorSchema(); 68 } 69 70 if (!isset($this->widgetSchema['article_list'])) 71 { 72 // somebody has unset this widget 73 return; 74 } 75 76 if (is_null($con)) 77 { 78 $con = $this->getConnection(); 79 } 80 81 $c = new Criteria(); 82 $c->add(AuthorArticlePeer::AUTHOR_ID, $this->object->getPrimaryKey()); 83 AuthorArticlePeer::doDelete($c, $con); 84 85 $values = $this->getValues(); 86 if (is_array($values['article_list'])) 87 { 88 foreach ($values['article_list'] as $value) 89 { 90 $obj = new AuthorArticle(); 91 $obj->setAuthorId($this->object->getPrimaryKey()); 92 $obj->setArticleId($value); 93 $obj->save(); 94 } 95 } 96 } 37 97 38 98 } branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/base/BaseBookForm.class.php
r6944 r7147 35 35 36 36 37 38 37 } branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/base/BaseCategoryForm.class.php
r6944 r7147 35 35 36 36 37 38 37 } branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/model/Author.php
r5103 r7147 10 10 class Author extends BaseAuthor 11 11 { 12 public function __toString() 13 { 14 return $this->getName(); 15 } 12 16 } branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/model/map/AuthorArticleMapBuilder.php
r5103 r7147 31 31 $tMap->setPhpName('AuthorArticle'); 32 32 33 $tMap->setUseIdGenerator( true);33 $tMap->setUseIdGenerator(false); 34 34 35 $tMap->addForeign Key('AUTHOR_ID', 'AuthorId', 'int', CreoleTypes::INTEGER, 'author', 'ID', false, null);35 $tMap->addForeignPrimaryKey('AUTHOR_ID', 'AuthorId', 'int' , CreoleTypes::INTEGER, 'author', 'ID', true, null); 36 36 37 $tMap->addForeignKey('ARTICLE_ID', 'ArticleId', 'int', CreoleTypes::INTEGER, 'article', 'ID', false, null); 38 39 $tMap->addPrimaryKey('ID', 'Id', 'int', CreoleTypes::INTEGER, true, null); 37 $tMap->addForeignPrimaryKey('ARTICLE_ID', 'ArticleId', 'int' , CreoleTypes::INTEGER, 'article', 'ID', true, null); 40 38 41 39 } branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/model/om/BaseAuthorArticle.php
r6882 r7147 16 16 protected $article_id; 17 17 18 19 20 protected $id;21 22 18 23 19 protected $aAuthor; … … 44 40 45 41 return $this->article_id; 46 }47 48 49 public function getId()50 {51 52 return $this->id;53 42 } 54 43 … … 90 79 } 91 80 92 public function setId($v)93 {94 95 if ($v !== null && !is_int($v) && is_numeric($v)) {96 $v = (int) $v;97 }98 99 if ($this->id !== $v) {100 $this->id = $v;101 $this->modifiedColumns[] = AuthorArticlePeer::ID;102 }103 104 }105 106 81 public function hydrate(ResultSet $rs, $startcol = 1) 107 82 { … … 112 87 $this->article_id = $rs->getInt($startcol + 1); 113 88 114 $this->id = $rs->getInt($startcol + 2);115 116 89 $this->resetModified(); 117 90 118 91 $this->setNew(false); 119 92 120 return $startcol + 3;93 return $startcol + 2; 121 94 } catch (Exception $e) { 122 95 throw new PropelException("Error populating AuthorArticle object", $e); … … 195 168 $pk = AuthorArticlePeer::doInsert($this, $con); 196 169 $affectedRows += 1; 197 $this->setId($pk);198 170 $this->setNew(false); 199 171 } else { … … 281 253 return $this->getArticleId(); 282 254 break; 283 case 2:284 return $this->getId();285 break;286 255 default: 287 256 return null; … … 296 265 $keys[0] => $this->getAuthorId(), 297 266 $keys[1] => $this->getArticleId(), 298 $keys[2] => $this->getId(),299 267 ); 300 268 return $result; … … 318 286 $this->setArticleId($value); 319 287 break; 320 case 2:321 $this->setId($value);322 break;323 288 } } 324 289 … … 330 295 if (array_key_exists($keys[0], $arr)) $this->setAuthorId($arr[$keys[0]]); 331 296 if (array_key_exists($keys[1], $arr)) $this->setArticleId($arr[$keys[1]]); 332 if (array_key_exists($keys[2], $arr)) $this->setId($arr[$keys[2]]);333 297 } 334 298 … … 340 304 if ($this->isColumnModified(AuthorArticlePeer::AUTHOR_ID)) $criteria->add(AuthorArticlePeer::AUTHOR_ID, $this->author_id); 341 305 if ($this->isColumnModified(AuthorArticlePeer::ARTICLE_ID)) $criteria->add(AuthorArticlePeer::ARTICLE_ID, $this->article_id); 342 if ($this->isColumnModified(AuthorArticlePeer::ID)) $criteria->add(AuthorArticlePeer::ID, $this->id);343 306 344 307 return $criteria; … … 350 313 $criteria = new Criteria(AuthorArticlePeer::DATABASE_NAME); 351 314 352 $criteria->add(AuthorArticlePeer::ID, $this->id); 315 $criteria->add(AuthorArticlePeer::AUTHOR_ID, $this->author_id); 316 $criteria->add(AuthorArticlePeer::ARTICLE_ID, $this->article_id); 353 317 354 318 return $criteria; … … 358 322 public function getPrimaryKey() 359 323 { 360 return $this->getId(); 361 } 362 363 364 public function setPrimaryKey($key) 365 { 366 $this->setId($key); 324 $pks = array(); 325 326 $pks[0] = $this->getAuthorId(); 327 328 $pks[1] = $this->getArticleId(); 329 330 return $pks; 331 } 332 333 334 public function setPrimaryKey($keys) 335 { 336 337 $this->setAuthorId($keys[0]); 338 339 $this->setArticleId($keys[1]); 340 367 341 } 368 342 … … 371 345 { 372 346 373 $copyObj->setAuthorId($this->author_id);374 375 $copyObj->setArticleId($this->article_id);376 377 347 378 348 $copyObj->setNew(true); 379 349 380 $copyObj->setId(NULL); 350 $copyObj->setAuthorId(NULL); 351 $copyObj->setArticleId(NULL); 381 352 } 382 353 branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/model/om/BaseAuthorArticlePeer.php
r6882 r7147 14 14 15 15 16 const NUM_COLUMNS = 3;16 const NUM_COLUMNS = 2; 17 17 18 18 … … 27 27 28 28 29 const ID = 'author_article.ID';30 31 32 29 private static $phpNameMap = null; 33 30 … … 35 32 36 33 private static $fieldNames = array ( 37 BasePeer::TYPE_PHPNAME => array ('AuthorId', 'ArticleId', 'Id',),38 BasePeer::TYPE_COLNAME => array (AuthorArticlePeer::AUTHOR_ID, AuthorArticlePeer::ARTICLE_ID, AuthorArticlePeer::ID,),39 BasePeer::TYPE_FIELDNAME => array ('author_id', 'article_id', 'id',),40 BasePeer::TYPE_NUM => array (0, 1, 2,)34 BasePeer::TYPE_PHPNAME => array ('AuthorId', 'ArticleId', ), 35 BasePeer::TYPE_COLNAME => array (AuthorArticlePeer::AUTHOR_ID, AuthorArticlePeer::ARTICLE_ID, ), 36 BasePeer::TYPE_FIELDNAME => array ('author_id', 'article_id', ), 37 BasePeer::TYPE_NUM => array (0, 1, ) 41 38 ); 42 39 43 40 44 41 private static $fieldKeys = array ( 45 BasePeer::TYPE_PHPNAME => array ('AuthorId' => 0, 'ArticleId' => 1, 'Id' => 2,),46 BasePeer::TYPE_COLNAME => array (AuthorArticlePeer::AUTHOR_ID => 0, AuthorArticlePeer::ARTICLE_ID => 1, AuthorArticlePeer::ID => 2,),47 BasePeer::TYPE_FIELDNAME => array ('author_id' => 0, 'article_id' => 1, 'id' => 2,),48 BasePeer::TYPE_NUM => array (0, 1, 2,)42 BasePeer::TYPE_PHPNAME => array ('AuthorId' => 0, 'ArticleId' => 1, ), 43 BasePeer::TYPE_COLNAME => array (AuthorArticlePeer::AUTHOR_ID => 0, AuthorArticlePeer::ARTICLE_ID => 1, ), 44 BasePeer::TYPE_FIELDNAME => array ('author_id' => 0, 'article_id' => 1, ), 45 BasePeer::TYPE_NUM => array (0, 1, ) 49 46 ); 50 47 … … 103 100 $criteria->addSelectColumn(AuthorArticlePeer::ARTICLE_ID); 104 101 105 $criteria->addSelectColumn(AuthorArticlePeer::ID); 106 107 } 108 109 const COUNT = 'COUNT(author_article.ID)'; 110 const COUNT_DISTINCT = 'COUNT(DISTINCT author_article.ID)'; 102 } 103 104 const COUNT = 'COUNT(author_article.AUTHOR_ID)'; 105 const COUNT_DISTINCT = 'COUNT(DISTINCT author_article.AUTHOR_ID)'; 111 106 112 107 … … 641 636 $criteria = $values->buildCriteria(); } 642 637 643 $criteria->remove(AuthorArticlePeer::ID);644 638 645 639 $criteria->setDbName(self::DATABASE_NAME); … … 668 662 if ($values instanceof Criteria) { 669 663 $criteria = clone $values; 670 $comparison = $criteria->getComparison(AuthorArticlePeer::ID); 671 $selectCriteria->add(AuthorArticlePeer::ID, $criteria->remove(AuthorArticlePeer::ID), $comparison); 664 $comparison = $criteria->getComparison(AuthorArticlePeer::AUTHOR_ID); 665 $selectCriteria->add(AuthorArticlePeer::AUTHOR_ID, $criteria->remove(AuthorArticlePeer::AUTHOR_ID), $comparison); 666 667 $comparison = $criteria->getComparison(AuthorArticlePeer::ARTICLE_ID); 668 $selectCriteria->add(AuthorArticlePeer::ARTICLE_ID, $criteria->remove(AuthorArticlePeer::ARTICLE_ID), $comparison); 672 669 673 670 } else { $criteria = $values->buildCriteria(); $selectCriteria = $values->buildPkeyCriteria(); } … … 708 705 } else { 709 706 $criteria = new Criteria(self::DATABASE_NAME); 710 $criteria->add(AuthorArticlePeer::ID, (array) $values, Criteria::IN); 707 if(count($values) == count($values, COUNT_RECURSIVE)) 708 { 709 $values = array($values); 710 } 711 $vals = array(); 712 foreach($values as $value) 713 { 714 715 $vals[0][] = $value[0]; 716 $vals[1][] = $value[1]; 717 } 718 719 $criteria->add(AuthorArticlePeer::AUTHOR_ID, $vals[0], Criteria::IN); 720 $criteria->add(AuthorArticlePeer::ARTICLE_ID, $vals[1], Criteria::IN); 711 721 } 712 722 … … 762 772 763 773 764 public static function retrieveByPK($pk, $con = null) 765 { 774 public static function retrieveByPK( $author_id, $article_id, $con = null) { 766 775 if ($con === null) { 767 776 $con = Propel::getConnection(self::DATABASE_NAME); 768 777 } 769 770 $criteria = new Criteria(AuthorArticlePeer::DATABASE_NAME); 771 772 $criteria->add(AuthorArticlePeer::ID, $pk); 773 774 778 $criteria = new Criteria(); 779 $criteria->add(AuthorArticlePeer::AUTHOR_ID, $author_id); 780 $criteria->add(AuthorArticlePeer::ARTICLE_ID, $article_id); 775 781 $v = AuthorArticlePeer::doSelect($criteria, $con); 776 782 777 return !empty($v) > 0 ? $v[0] : null; 778 } 779 780 781 public static function retrieveByPKs($pks, $con = null) 782 { 783 if ($con === null) { 784 $con = Propel::getConnection(self::DATABASE_NAME); 785 } 786 787 $objs = null; 788 if (empty($pks)) { 789 $objs = array(); 790 } else { 791 $criteria = new Criteria(); 792 $criteria->add(AuthorArticlePeer::ID, $pks, Criteria::IN); 793 $objs = AuthorArticlePeer::doSelect($criteria, $con); 794 } 795 return $objs; 796 } 797 783 return !empty($v) ? $v[0] : null; 784 } 798 785 } 799 786 if (Propel::isInit()) {