function testNullDate() { $emp = new Employe(array('firstname' => 'Steve', 'lastname' => 'Austin')); $emp->save(); $emp = SActiveStore::findFirst('Employe'); $this->assertNull($emp->date_of_birth); }
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'])); }
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']); } }
protected function bottomItem() { return SActiveStore::findFirst(get_class($this), $this->scopeCondition(), array('order' => "{$this->positionField()} DESC")); }
protected function bottomItem() { return SActiveStore::findFirst(get_class($this->record), $this->scopeCondition(), array('order' => "{$this->column} DESC")); }
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); }
protected function findTarget() { return SActiveStore::findFirst($this->assocClass, $this->constructSql()); }