コード例 #1
0
ファイル: basics.php プロジェクト: AF83/morm
 public function testGetData()
 {
     $author = new Authors(array('name' => 'Chuck Norris'));
     $author->save();
     $post = new Mormons('authors');
     $this->assertEqual('Chuck Norris', $post->first()->name);
     $this->assertEqual(1, $post->first()->id);
 }
コード例 #2
0
ファイル: Cerbere.php プロジェクト: AF83/morm
 public function execute()
 {
     $this->executeSphinxQuery();
     if (!empty($this->sphinx_results['matches'])) {
         $ids = array();
         foreach ($this->sphinx_results['matches'] as $match) {
             $ids[] = $match['attrs'][strtolower($this->base_class) . '_id'];
         }
         $this->add_conditions(array($this->base_models[$this->base_table]->getPkey() => $ids));
         parent::execute();
     } else {
         $this->_executed = true;
         $this->mormons = array();
         $this->mormon_keys = array_keys($this->mormons);
         $this->nb_mormons = 0;
     }
 }
コード例 #3
0
ファイル: sti.php プロジェクト: AF83/morm
 public function testInstanceSTI()
 {
     $this->user = $this->createEntry('OtherUser', array('name' => 'John Doe', 'othertype' => 'corrector'));
     $user = new Mormons('otheruser');
     $this->assertIsA($user->first(), 'Corrector');
 }
コード例 #4
0
ファイル: Morm.php プロジェクト: anicet/morm
 /**
  * loadForeignObjectFromMormons 
  * 
  * same as loadForeignObject but from an associated mormon so that the 
  * objects keep a reference between themselves
  *
  * @throws exception if the given alias_or_table is not declared in the 
  * has_many hash
  * @param string $alias_or_table 
  * @param array $to_load 
  * @return void
  */
 public function loadForeignObjectFromMormons($alias_or_table, $to_load = null)
 {
     if ($this->isForeignMormons($alias_or_table)) {
         $table = $this->getForeignMormonsTable($alias_or_table);
         if (is_null($to_load)) {
             $mormons = new Mormons($table);
             //TODO manage multiple primary keys
             $mormons->add_conditions(array($this->getForeignMormonsKey($alias_or_table) => $this->{$this->_pkey}));
             if (isset($this->_has_many[$alias_or_table]['condition'])) {
                 $mormons->add_conditions($this->_has_many[$alias_or_table]['condition']);
             }
             if (isset($this->_has_many[$alias_or_table]['order'])) {
                 foreach ($this->_has_many[$alias_or_table]['order'] as $field => $direction) {
                     $mormons->set_order($field);
                     $mormons->set_order_dir($direction);
                 }
             }
             $mormons->associateForeignObject($this->_pkey, $this);
             $this->_foreign_mormons[$alias_or_table] = $mormons;
         } else {
             if (!isset($this->_foreign_mormons[$alias_or_table])) {
                 $this->loadForeignObjectFromMormons($alias_or_table);
             }
             $this->_foreign_mormons[$alias_or_table]->addMormFromArray($table, $to_load, $this);
         }
     } else {
         throw new Exception(get_class($this) . " does not have many " . $alias_or_table . "s");
     }
 }
コード例 #5
0
ファイル: oneToMany.php プロジェクト: AF83/morm
 public function testSetJoin()
 {
     $books = new Mormons('books');
     $books->set_join('authors');
     foreach ($books as $book) {
         $this->assertEqual(1, count($book->getForeignObjectForTesting()));
     }
 }