public function testCustomeFields() { $q = UserModel::objects()->limit(5)->values(['user_id', 'username']); foreach ($q as $obj) { $this->assertCount(2, $obj); } }
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]); }
public function testRefresh() { $obj = UserModel::objects()->get(1); $initial = $obj->username; $obj->username = '******'; $obj->refresh(); $this->assertEquals($initial, $obj->username); }
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()); }
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); }
public function testUsing() { $conn = Dja\Db\Model\Metadata::getDefaultDbConnection(); $q = UserModel::objects()->limit(5)->using($conn); $q->count(); }
public function testBase() { $q = UserModel::objects()->filter(['pk__lt' => 10])->limit(1); $obj = $q->current(); $this->assertEquals($obj->slug, slugify($obj->fullname)); }