Пример #1
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']);
 }
Пример #2
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;
 }
Пример #3
0
 private function findTarget($record)
 {
     $foreignKeyId = $record->id();
     $ownForeignKey = $this->createForeignKey($this->source());
     $conditions = ['where' => ['field' => $ownForeignKey, 'comparision' => '=', 'value' => $foreignKeyId]];
     $conditions = $this->mergeOption($conditions);
     $linkTable = $this->linkTable();
     $links = BaseRecord::whereAll($linkTable, $conditions);
     $targetForeignKey = $this->createForeignKey($this->target());
     $recordClass = $this->target();
     $results = [];
     foreach ($links as $target) {
         $targetTable = $this->createTableName($this->target());
         $recordName = $this->recordNamespace($this->target());
         $find = BaseRecord::whereAll($targetTable, ['where' => ['field' => 'id', 'comparision' => '=', 'value' => $target[$targetForeignKey]]], $recordName);
         if (count($find) !== 0 || $find !== false) {
             $record = array_shift($find);
             $results[] = $record;
         }
     }
     return $results;
 }
Пример #4
0
 public function testWhereAll()
 {
     $record = BaseRecord::whereAll('mocks', ['where' => ['field' => 'name', 'comparision' => '=', 'value' => 'bar']], '\\App\\Model\\Mock');
     $this->assertEquals('bar', $record[0]->name);
 }