Exemplo n.º 1
0
 public function testPlurals()
 {
     $plurals = \Gini\Config::get('orm.plurals');
     $plurals['users'] = 'user';
     \Gini\Config::set('orm.plurals', $plurals);
     // e.g. those('users')
     \Gini\Those::reset();
     $those = those('users')->whose('name')->beginsWith('COOL');
     $those->makeSQL();
     $this->assertAttributeEquals('SELECT DISTINCT "t0"."id" FROM "user" AS "t0" WHERE "t0"."name" LIKE \'COOL%\'', 'SQL', $those);
 }
Exemplo n.º 2
0
 public function testInObjects()
 {
     // e.g. those('users')
     \Gini\Those::reset();
     $those = those('users')->whose('gender')->is(1)->andWhose('father')->isIn(those('users')->whose('name')->is('A'));
     $those->makeSQL();
     $this->assertAttributeEquals('SELECT DISTINCT "t0"."id" FROM "user" AS "t0" INNER JOIN "user" AS "t1" ON "t0"."father_id"="t1"."id" WHERE "t0"."gender"=1 AND "t1"."name"=\'A\'', 'SQL', $those);
     \Gini\Those::reset();
     $those = those('users')->whose('gender')->is(1)->orWhose('father')->isIn(those('users')->whose('name')->is('A'));
     $those->makeSQL();
     $this->assertAttributeEquals('SELECT DISTINCT "t0"."id" FROM "user" AS "t0" INNER JOIN "user" AS "t1" ON "t0"."father_id"="t1"."id" WHERE "t0"."gender"=1 OR "t1"."name"=\'A\'', 'SQL', $those);
     \Gini\Those::reset();
     $those = those('users')->whose('gender')->is(1)->andWhose('father')->isNotIn(those('users')->whose('name')->is('A'));
     $those->makeSQL();
     $this->assertAttributeEquals('SELECT DISTINCT "t0"."id" FROM "user" AS "t0" LEFT JOIN "user" AS "t1" ON "t0"."father_id"="t1"."id" WHERE "t0"."gender"=1 AND "t0"."father_id" IS NOT NULL AND "t1"."name"=\'A\'', 'SQL', $those);
 }