Development

Changeset 7147

You must first sign up to be able to contribute.

Changeset 7147

Show
Ignore:
Timestamp:
01/22/08 12:11:01 (10 months ago)
Author:
fabien
Message:

fixed performance issue with foreign keys in Propel generated forms

  • added 2 validators: sfValidatorPropelChoice, sfValidatorPropelChoiceMany
  • added 2 widgets: sfWidgetFormPropelSelect, sfWidgetFormPropelSelectMany
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.1/lib/plugins/sfPropelPlugin/data/generator/sfPropelForm/default/template/sfPropelFormGeneratedTemplate.php

    r7055 r7147  
    1818<?php endforeach; ?> 
    1919<?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 sfWidgetFormSelectMany(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() ?>')), 
    2121<?php endforeach; ?> 
    2222    )); 
     
    2727<?php endforeach; ?> 
    2828<?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 sfValidatorChoiceMany(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)), 
    3030<?php endforeach; ?> 
    3131    )); 
     
    5555<?php endif; ?> 
    5656 
    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  
    7857<?php if ($this->getManyToManyTables()): ?> 
    7958  public function updateDefaultsFromObject() 
     
    9271      $this->setDefault('<?php echo $tables['relatedTable']->getName() ?>_list', $values); 
    9372    } 
     73 
    9474<?php endforeach; ?> 
    9575  } 
     
    139119    } 
    140120  } 
     121 
    141122<?php endforeach; ?> 
    142123<?php endif; ?> 
  • branches/1.1/lib/plugins/sfPropelPlugin/lib/propel/generator/sfPropelFormGenerator.class.php

    r7055 r7147  
    226226    else if ($column->isForeignKey()) 
    227227    { 
    228       $name = 'Select'; 
     228      $name = 'PropelSelect'; 
    229229    } 
    230230 
     
    245245    if (!$column->isPrimaryKey() && $column->isForeignKey()) 
    246246    { 
    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'); 
    248248    } 
    249249 
     
    299299    if (!$column->isPrimaryKey() && $column->isForeignKey()) 
    300300    { 
    301       $name = 'Choice'; 
     301      $name = 'PropelChoice'; 
    302302    } 
    303303 
     
    331331    if (!$column->isPrimaryKey() && $column->isForeignKey()) 
    332332    { 
    333       $options[] = sprintf('\'choices\' => new sfCallable(array($this, \'get%sIdentifierChoices\'))', $column->getPhpName()); 
     333      $options[] = sprintf('\'model\' => \'%s\'', $this->getForeignTable($column)->getPhpName()); 
    334334    } 
    335335 
  • branches/1.1/lib/plugins/sfPropelPlugin/test/functional/crud/crudBrowser.class.php

    r6950 r7147  
    9494        'end_date'    => array('year' => '', 'month' => '', 'day' => '', 'hour' => '', 'minute' => ''), 
    9595        'book_id'     => 0, 
     96        'author_list' => array(), 
    9697      )) 
    9798    ; 
     
    106107      'end_date'    => array('year' => '', 'month' => '', 'day' => '', 'hour' => '', 'minute' => ''), 
    107108      'book_id'     => null, 
     109      'author_list' => array(1, 2), 
    108110    ), 3); 
    109111 
     
    139141      checkResponseElement('table tbody th:nth(5)', 'End date')-> 
    140142      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)-> 
    144147      checkResponseElement('table tbody td select[id="article_category_id"][name="article[category_id]"] option', 2)-> 
    145148      checkResponseElement('table tbody td select[id="article_book_id"][name="article[book_id]"] option', 2) 
     
    155158      'end_date'    => array('year' => 0, 'month' => 0, 'day' => 15, 'hour' => '10', 'minute' => '20'), 
    156159      'book_id'     => 14, 
     160      'author_list' => array(0, 5), 
    157161    ); 
    158162    $this-> 
     
    165169      )-> 
    166170      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
    168172    ; 
    169173 
     
    177181      'end_date'    => array('year' => 2005, 'month' => 10, 'day' => 15, 'hour' => '10', 'minute' => '20'), 
    178182      'book_id'     => 1, 
     183      'author_list' => array(1, 3), 
    179184    ), 3); 
    180185 
     
    278283      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')-> 
    279284 
     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 
    280289      checkResponseElement('table tbody td select[id="article_end_date_year"][name="article[end_date][year]"] option[selected="selected"]', (string) $values['end_date']['year'])-> 
    281290      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  
    3535 
    3636  <table name="author_article"> 
    37     <column name="author_id" type="integer" /> 
     37    <column name="author_id" type="integer" primaryKey="true" /> 
    3838    <foreign-key foreignTable="author"> 
    3939      <reference local="author_id" foreign="id" /> 
    4040    </foreign-key> 
    41     <column name="article_id" type="integer" /> 
     41    <column name="article_id" type="integer" primaryKey="true" /> 
    4242    <foreign-key foreignTable="article"> 
    4343      <reference local="article_id" foreign="id" /> 
    4444    </foreign-key> 
    45     <column name="id" type="integer" required="true" primaryKey="true" autoincrement="true" /> 
    4645  </table> 
    4746 
  • branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/data/sql/lib.model.schema.sql

    r5103 r7147  
    1010( 
    1111  [id] INTEGER  NOT NULL PRIMARY KEY, 
    12   [title] VARCHAR(255)
     12  [title] VARCHAR(255)  NOT NULL
    1313  [body] MEDIUMTEXT, 
    1414  [online] INTEGER, 
     
    7373CREATE TABLE [author_article] 
    7474( 
    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 
    7877); 
    7978 
  • branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/base/BaseArticleForm.class.php

    r6944 r7147  
    1717      'body'        => new sfWidgetFormTextarea(), 
    1818      'online'      => new sfWidgetFormInputCheckbox(), 
    19       'category_id' => new sfWidgetFormSelect(array('choices' => new sfCallable(array($this, 'getCategoryChoices')))), 
     19      'category_id' => new sfWidgetFormPropelSelect(array('model' => 'Category', 'add_empty' => false)), 
    2020      'created_at'  => new sfWidgetFormDateTime(), 
    2121      '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')), 
    2324    )); 
    2425 
     
    2829      'body'        => new sfValidatorString(array('required' => false)), 
    2930      'online'      => new sfValidatorBoolean(array('required' => false)), 
    30       'category_id' => new sfValidatorChoice(array('choices' => new sfCallable(array($this, 'getCategoryIdentifierChoices')))), 
     31      'category_id' => new sfValidatorPropelChoice(array('model' => 'Category')), 
    3132      'created_at'  => new sfValidatorDateTime(array('required' => false)), 
    3233      '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)), 
    3436    )); 
    3537 
     
    4749 
    4850 
    49   public function getCategoryIdentifierChoices() 
     51  public function updateDefaultsFromObject() 
    5052  { 
    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 
    5266  } 
    5367 
    54   public function getCategoryChoices(
     68  protected function doSave($con = null
    5569  { 
    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()) 
    5778    { 
    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) 
    60101      { 
    61         $this->CategoryChoices[$object->getId()] = $object->__toString(); 
     102        $obj = new AuthorArticle(); 
     103        $obj->setArticleId($this->object->getPrimaryKey()); 
     104        $obj->setAuthorId($value); 
     105        $obj->save(); 
    62106      } 
    63107    } 
    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; 
    84108  } 
    85109 
  • branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/base/BaseAuthorArticleForm.class.php

    r6944 r7147  
    1313  { 
    1414    $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(), 
    1817    )); 
    1918 
    2019    $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)), 
    2422    )); 
    2523 
     
    3735 
    3836 
    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  
    7637} 
  • branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/base/BaseAuthorForm.class.php

    r6944 r7147  
    1313  { 
    1414    $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')), 
    1718    )); 
    1819 
    1920    $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)), 
    2224    )); 
    2325 
     
    3537 
    3638 
     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  } 
    3797 
    3898} 
  • branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/base/BaseBookForm.class.php

    r6944 r7147  
    3535 
    3636 
    37  
    3837} 
  • branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/base/BaseCategoryForm.class.php

    r6944 r7147  
    3535 
    3636 
    37  
    3837} 
  • branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/model/Author.php

    r5103 r7147  
    1010class Author extends BaseAuthor 
    1111{ 
     12  public function __toString() 
     13  { 
     14    return $this->getName(); 
     15  } 
    1216} 
  • branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/model/map/AuthorArticleMapBuilder.php

    r5103 r7147  
    3131    $tMap->setPhpName('AuthorArticle'); 
    3232 
    33     $tMap->setUseIdGenerator(true); 
     33    $tMap->setUseIdGenerator(false); 
    3434 
    35     $tMap->addForeignKey('AUTHOR_ID', 'AuthorId', 'int', CreoleTypes::INTEGER, 'author', 'ID', false, null); 
     35    $tMap->addForeignPrimaryKey('AUTHOR_ID', 'AuthorId', 'int' , CreoleTypes::INTEGER, 'author', 'ID', true, null); 
    3636 
    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); 
    4038 
    4139  }  
  • branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/model/om/BaseAuthorArticle.php

    r6882 r7147  
    1616  protected $article_id; 
    1717 
    18  
    19    
    20   protected $id; 
    21  
    2218   
    2319  protected $aAuthor; 
     
    4440 
    4541    return $this->article_id; 
    46   } 
    47  
    48    
    49   public function getId() 
    50   { 
    51  
    52     return $this->id; 
    5342  } 
    5443 
     
    9079  }  
    9180   
    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    
    10681  public function hydrate(ResultSet $rs, $startcol = 1) 
    10782  { 
     
    11287      $this->article_id = $rs->getInt($startcol + 1); 
    11388 
    114       $this->id = $rs->getInt($startcol + 2); 
    115  
    11689      $this->resetModified(); 
    11790 
    11891      $this->setNew(false); 
    11992 
    120             return $startcol + 3;  
     93            return $startcol + 2;  
    12194    } catch (Exception $e) { 
    12295      throw new PropelException("Error populating AuthorArticle object", $e); 
     
    195168          $pk = AuthorArticlePeer::doInsert($this, $con); 
    196169          $affectedRows += 1;                                           
    197           $this->setId($pk);   
    198170          $this->setNew(false); 
    199171        } else { 
     
    281253        return $this->getArticleId(); 
    282254        break; 
    283       case 2: 
    284         return $this->getId(); 
    285         break; 
    286255      default: 
    287256        return null; 
     
    296265      $keys[0] => $this->getAuthorId(), 
    297266      $keys[1] => $this->getArticleId(), 
    298       $keys[2] => $this->getId(), 
    299267    ); 
    300268    return $result; 
     
    318286        $this->setArticleId($value); 
    319287        break; 
    320       case 2: 
    321         $this->setId($value); 
    322         break; 
    323288    }   } 
    324289 
     
    330295    if (array_key_exists($keys[0], $arr)) $this->setAuthorId($arr[$keys[0]]); 
    331296    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]]); 
    333297  } 
    334298 
     
    340304    if ($this->isColumnModified(AuthorArticlePeer::AUTHOR_ID)) $criteria->add(AuthorArticlePeer::AUTHOR_ID, $this->author_id); 
    341305    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); 
    343306 
    344307    return $criteria; 
     
    350313    $criteria = new Criteria(AuthorArticlePeer::DATABASE_NAME); 
    351314 
    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); 
    353317 
    354318    return $criteria; 
     
    358322  public function getPrimaryKey() 
    359323  { 
    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 
    367341  } 
    368342 
     
    371345  { 
    372346 
    373     $copyObj->setAuthorId($this->author_id); 
    374  
    375     $copyObj->setArticleId($this->article_id); 
    376  
    377347 
    378348    $copyObj->setNew(true); 
    379349 
    380     $copyObj->setId(NULL);  
     350    $copyObj->setAuthorId(NULL);  
     351    $copyObj->setArticleId(NULL);  
    381352  } 
    382353 
  • branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/model/om/BaseAuthorArticlePeer.php

    r6882 r7147  
    1414 
    1515   
    16   const NUM_COLUMNS = 3
     16  const NUM_COLUMNS = 2
    1717 
    1818   
     
    2727 
    2828   
    29   const ID = 'author_article.ID'; 
    30  
    31    
    3229  private static $phpNameMap = null; 
    3330 
     
    3532   
    3633  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,
    4138  ); 
    4239 
    4340   
    4441  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,
    4946  ); 
    5047 
     
    103100    $criteria->addSelectColumn(AuthorArticlePeer::ARTICLE_ID); 
    104101 
    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)'; 
    111106 
    112107   
     
    641636      $criteria = $values->buildCriteria();     } 
    642637 
    643     $criteria->remove(AuthorArticlePeer::ID);  
    644638 
    645639        $criteria->setDbName(self::DATABASE_NAME); 
     
    668662    if ($values instanceof Criteria) { 
    669663      $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); 
    672669 
    673670    } else {      $criteria = $values->buildCriteria();       $selectCriteria = $values->buildPkeyCriteria();     } 
     
    708705    } else { 
    709706            $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); 
    711721    } 
    712722 
     
    762772 
    763773   
    764   public static function retrieveByPK($pk, $con = null) 
    765   { 
     774  public static function retrieveByPK( $author_id, $article_id, $con = null) { 
    766775    if ($con === null) { 
    767776      $con = Propel::getConnection(self::DATABASE_NAME); 
    768777    } 
    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); 
    775781    $v = AuthorArticlePeer::doSelect($criteria, $con); 
    776782 
    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  } 
    798785}  
    799786if (Propel::isInit()) {