public static function setUpBeforeClass() { $config = (require '../config.php'); self::$connection = new MySql($config['Database']['MySql']); self::$operator = new RecordOperator(self::$connection, new RecordProperty()); BaseRecord::setConnection(self::$connection); }
public function testBelongsToSideValidate() { $mockdependent = Mockdependent::read(1); $mockdependent->name = 'modified'; $mockdependent->Mock->name = ''; $mockdependent->saveAtomic(); $subject = BaseRecord::whereAll('mocks', ['where' => ['field' => 'id', 'comparision' => '=', 'value' => 1]]); $dependent = BaseRecord::whereAll('mockdependents', ['where' => ['field' => 'id', 'comparision' => '=', 'value' => 1]]); /* * validationエラーが起こった場合 */ $this->assertEquals('foo', $subject->fetch()['name']); $this->assertEquals('bar', $dependent->fetch()['name']); $this->assertEquals('name error', Mock::flashError()); $mockdependent->name = 'modified'; $mockdependent->Mock->name = 'modified'; $mockdependent->saveAtomic(); $subject = BaseRecord::whereAll('mocks', ['where' => ['field' => 'id', 'comparision' => '=', 'value' => 1]]); $dependent = BaseRecord::whereAll('mockdependents', ['where' => ['field' => 'id', 'comparision' => '=', 'value' => 1]]); /* * validationエラーが起こらなかった場合 */ $this->assertEquals('modified', $subject->fetch()['name']); $this->assertEquals('modified', $dependent->fetch()['name']); }
public function testUpdateAll() { $record = Mock::create(['name' => 'new']); $this->assertEquals(true, BaseRecord::updateAll(Mock::tableName(), ['name' => 'modified'], $record->id)); /* * BaseRecord::updateAllはオブジェクトをIdentityMapに登録しないのでNotEqual */ $this->assertNotEquals('modified', Mock::read($record->id)->name); }
public function find($record) { $foreignKey = $this->createForeignKey($this->source()); $foreignKeyId = $record->id(); $conditions = ['where' => ['field' => $foreignKey, 'comparision' => '=', 'value' => $foreignKeyId]]; $conditions = $this->mergeOption($conditions); $targetTable = $this->createTableName($this->target()); $recordName = $this->recordNamespace($this->target()); $results = BaseRecord::whereAll($targetTable, $conditions, $recordName); if (count($results) === 0 || $results === false) { $hasOne = null; } else { $hasOne = array_shift($results); } return $hasOne; }
static function setUpBeforeClass() { $config = (require 'config.php'); self::$conn = new MySql($config['Database']['MySql']); BaseRecord::setConnection(self::$conn); }
<?php use TRW\Core\Configure; use TRW\Router\Router; use TRW\ActiveRecord\BaseRecord; use TRW\ActiveRecord\Database\Driver\MySql; use TRW\Exception\ErrorHandler; //ini_set('display_errors',1); Configure::load(dirname(__FILE__) . '/config.php'); set_exception_handler('TRW\\Exception\\ErrorHandler::handleException'); BaseRecord::setConnection(new MySql(Configure::read('Database', 'MySql'))); Router::add('/', ['controller' => 'Pages', 'action' => 'index']);
public function deleteLinkTable($record) { $linkTable = $this->linkTable(); $property = $this->target(); $associated = $record->{$property}; $targetForeignKey = $this->createForeignKey($this->target()); if (empty($associated)) { return true; } foreach ($associated as $obj) { $success = BaseRecord::deleteAll($linkTable, $obj->primaryKey(), '=', $obj->id()); if (!$success) { return false; } } return true; }
public function setUp() { Configure::load('../app/config/config.php'); BaseRecord::setConnection(new MySql(Configure::read('Database', 'MySql'))); }
/** * データベーステーブルのスキーマを返す. * * @return array データベーステーブルのスキーマ */ public function schema() { if (empty($this->schema)) { $this->schema = BaseRecord::schema($this->table); } return $this->schema; }
public static function setUpBeforeClass() { $config = (require 'config.php'); self::$connection = $connection = new MySql($config); BaseRecord::setConnection($connection); }