Пример #1
0
 public function testCustomeFields()
 {
     $q = UserModel::objects()->limit(5)->values(['user_id', 'username']);
     foreach ($q as $obj) {
         $this->assertCount(2, $obj);
     }
 }
Пример #2
0
 public function testFilterIn3()
 {
     $q1 = UserModel::objects()->filter(['user_id__in' => [1, 2, 3, 4, 5]])->valuesList('pk', false);
     $q2 = CustomerOrderModel::objects()->filter(['user__in' => $q1]);
     $obj = $q2->current();
     $this->assertInstanceOf('\\Dja\\Db\\Model\\Model', $obj);
     $this->assertContains($obj->user_id, [1, 2, 3, 4, 5]);
 }
Пример #3
0
 public function testRefresh()
 {
     $obj = UserModel::objects()->get(1);
     $initial = $obj->username;
     $obj->username = '******';
     $obj->refresh();
     $this->assertEquals($initial, $obj->username);
 }
Пример #4
0
 public function testGetOrCreate()
 {
     $obj = UserModel::objects()->getOrCreate(['user_id' => 1]);
     $this->assertInstanceOf('\\UserModel', $obj);
     $this->assertFalse($obj->isNewRecord());
     $obj = UserModel::objects()->getOrCreate(['user_id' => 99999]);
     $this->assertInstanceOf('\\UserModel', $obj);
     $this->assertTrue($obj->isNewRecord());
 }
Пример #5
0
 public function testSelectingCached()
 {
     $countQ1 = count(SqlLog::$log->queries);
     $q = UserModel::objects()->raw('SELECT * FROM :t LIMIT 5');
     foreach ($q->cached() as $obj) {
         $this->assertInstanceOf('\\Dja\\Db\\Model\\Model', $obj);
     }
     foreach ($q->cached() as $obj) {
         $this->assertInstanceOf('\\Dja\\Db\\Model\\Model', $obj);
     }
     $countQ2 = count(SqlLog::$log->queries);
     $this->assertEquals(1, $countQ2 - $countQ1);
 }
Пример #6
0
 public function testUsing()
 {
     $conn = Dja\Db\Model\Metadata::getDefaultDbConnection();
     $q = UserModel::objects()->limit(5)->using($conn);
     $q->count();
 }
Пример #7
0
 public function testBase()
 {
     $q = UserModel::objects()->filter(['pk__lt' => 10])->limit(1);
     $obj = $q->current();
     $this->assertEquals($obj->slug, slugify($obj->fullname));
 }