コード例 #1
0
 function testNullDate()
 {
     $emp = new Employe(array('firstname' => 'Steve', 'lastname' => 'Austin'));
     $emp->save();
     $emp = SActiveStore::findFirst('Employe');
     $this->assertNull($emp->date_of_birth);
 }
コード例 #2
0
 function testLoadingWithOneAssociation()
 {
     $articles = SActiveStore::findAll('Article', Null, array('include' => array('comments')));
     $this->assertTrue($articles[0]->comments->isLoaded());
     $this->assertTrue($articles[1]->comments->isLoaded());
     // the assoc must be flagged as loaded even if empty
     $this->assertEqual(2, $articles[0]->countComments());
     $this->assertEqual(0, $articles[1]->countComments());
     $this->assertTrue($articles[0]->comments->contains($this->comments['comment_1']));
     $article = SActiveStore::findFirst('Article', "articles.title='PHP6 overview'", array('include' => array('comments')));
     $this->assertTrue($article->comments->isLoaded());
     $this->assertEqual(2, $article->countComments());
     $this->assertTrue($article->comments->contains($this->comments['comment_1']));
 }
コード例 #3
0
 public static function validateUniqueness($record, $attr, $options = array())
 {
     $config = array('message' => 'ERR_VALID_UNIQUE', 'on' => 'save', 'scope' => Null);
     $config = array_merge($config, $options);
     $value = $record->{$attr};
     $conditionsSql = $attr . ' ' . self::attributeCondition($value);
     $conditionsValues = array($value);
     if ($config['scope'] !== Null) {
         $scopeValue = $record->readAttribute($config['scope']);
         $conditionsSql .= ' AND ' . $config['scope'] . ' ' . self::attributeCondition($scopeValue);
         $conditionsValues[] = $scopeValue;
     }
     if (!$record->isNewRecord()) {
         $conditionsSql .= ' AND ' . $record->identityField . ' <> ?';
         $conditionsValues[] = $record->id;
     }
     if (SActiveStore::findFirst(get_class($record), array($conditionsSql, $conditionsValues))) {
         self::addError($record, $attr, $config['message']);
     }
 }
コード例 #4
0
 protected function bottomItem()
 {
     return SActiveStore::findFirst(get_class($this), $this->scopeCondition(), array('order' => "{$this->positionField()} DESC"));
 }
コード例 #5
0
 protected function bottomItem()
 {
     return SActiveStore::findFirst(get_class($this->record), $this->scopeCondition(), array('order' => "{$this->column} DESC"));
 }
コード例 #6
0
 public function testMigratorGoingDownDueToVersionTarget()
 {
     SMigrator::up(dirname(__FILE__) . '/fixtures/migrate', 1);
     SMigrator::migrate(dirname(__FILE__) . '/fixtures/migrate', 0);
     $this->assertFalse(in_array('last_name', array_keys(SActiveRecord::connection()->columns('people'))));
     $this->assertFalse(SActiveStore::tableExists('reminders'));
     SMigrator::migrate(dirname(__FILE__) . '/fixtures/migrate');
     $this->assertEqual(2, SMigrator::currentVersion());
     SActiveStore::resetAttributeInformation('people');
     $this->assertTrue(in_array('last_name', array_keys(SActiveRecord::connection()->columns('people'))));
     $r = new Reminder(array('content' => 'hello world', 'remind_at' => SDateTime::today()));
     $r->save();
     $this->assertEqual('hello world', SActiveStore::findFirst('reminder')->content);
 }
コード例 #7
0
 protected function findTarget()
 {
     return SActiveStore::findFirst($this->assocClass, $this->constructSql());
 }