예제 #1
0
 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);
 }
예제 #2
0
 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']);
 }
예제 #3
0
 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);
 }
예제 #4
0
 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;
 }
예제 #5
0
 static function setUpBeforeClass()
 {
     $config = (require 'config.php');
     self::$conn = new MySql($config['Database']['MySql']);
     BaseRecord::setConnection(self::$conn);
 }
예제 #6
0
<?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']);
예제 #7
0
 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;
 }
예제 #8
0
 public function setUp()
 {
     Configure::load('../app/config/config.php');
     BaseRecord::setConnection(new MySql(Configure::read('Database', 'MySql')));
 }
예제 #9
0
 /**
 * データベーステーブルのスキーマを返す.
 *
 * @return array データベーステーブルのスキーマ
 */
 public function schema()
 {
     if (empty($this->schema)) {
         $this->schema = BaseRecord::schema($this->table);
     }
     return $this->schema;
 }
예제 #10
0
 public static function setUpBeforeClass()
 {
     $config = (require 'config.php');
     self::$connection = $connection = new MySql($config);
     BaseRecord::setConnection($connection);
 }