Example #1
0
         expect($result->meta())->toEqual(['count' => 6]);
     });
 });
 describe("->offset()", function () {
     it("returns records at a specific offset", function () {
         $this->fixtures->populate('tag');
         $query = new Query(['model' => $this->tag]);
         $result = $query->order(['id'])->offset(0)->limit(3)->all()->data();
         expect($result)->toEqual([['id' => '1', 'name' => 'High Tech'], ['id' => '2', 'name' => 'Sport'], ['id' => '3', 'name' => 'Computer']]);
         $result = $query->order(['id'])->offset(3)->limit(3)->all()->data();
         expect($result)->toEqual([['id' => '4', 'name' => 'Art'], ['id' => '5', 'name' => 'Science'], ['id' => '6', 'name' => 'City']]);
     });
     it("populates the meta count value", function () {
         $this->fixtures->populate('tag');
         $query = new Query(['model' => $this->tag]);
         $result = $query->order(['id'])->offset(3)->limit(3)->all();
         expect($result->meta())->toEqual(['count' => 6]);
     });
 });
 describe("->embed()", function () {
     it("gets/sets with relationship", function () {
         $query = new Query(['schema' => new Schema(['connection' => $this->connection])]);
         $query->embed('relation1.relation2');
         $query->embed('relation3', ['conditions' => ['title' => 'hello world']]);
         expect($query->embed())->toBe(['relation1.relation2' => [], 'relation3' => ['conditions' => ['title' => 'hello world']]]);
     });
     it("loads external relations embed a custom condition on tags", function () {
         $this->fixtures->populate('gallery');
         $this->fixtures->populate('image');
         $this->fixtures->populate('image_tag');
         $this->fixtures->populate('tag');
Example #2
0
         $result = $query->fields(['gallery_id'])->group('gallery_id')->get();
         expect(count($result))->toBe(2);
     });
 });
 describe("->having()", function () {
     it("filters out according conditions", function () {
         $this->fixtures->populate('gallery');
         $result = $this->query->fields(['name'])->group('name')->having(['name' => 'Foo Gallery'])->get();
         expect(count($result))->toBe(1);
     });
 });
 describe("->order()", function () {
     it("order by a field name ASC", function () {
         $this->fixtures->populate('gallery');
         $query = new Query(['model' => $this->gallery, 'connection' => $this->connection]);
         $entity = $query->order(['name' => 'ASC'])->first();
         expect($entity->name)->toBe('Bar Gallery');
         $entity = $this->query->order('name')->first();
         expect($entity->name)->toBe('Bar Gallery');
     });
     it("order by a field name DESC", function () {
         $this->fixtures->populate('gallery');
         $entity = $this->query->order(['name' => 'DESC'])->first();
         expect($entity->name)->toBe('Foo Gallery');
     });
 });
 describe("->embed()", function () {
     it("gets/sets with relationship", function () {
         $query = new Query(['connection' => $this->connection]);
         $query->embed('relation1.relation2');
         $query->embed('relation3', ['conditions' => ['title' => 'hello world']]);