Inheritance: extends Pheasant\DomainObject
Exemple #1
0
 public static function createHelper($alias, $identity, $powers = array())
 {
     $hero = new Hero(array('alias' => $alias));
     $hero->save();
     $identity = new SecretIdentity(array('realname' => $identity));
     $hero->SecretIdentity = $identity;
     $identity->save();
     foreach ($powers as $power) {
         $power = new Power(array('description' => $power));
         $hero->Powers[] = $power;
         $power->save();
     }
     $hero->save();
     return $hero;
 }
Exemple #2
0
 public function testIncludesHitsCache()
 {
     $queries = 0;
     $this->connection()->filterChain()->onQuery(function ($sql) use(&$queries) {
         ++$queries;
         return $sql;
     });
     // the first lookup of SecretIdentity should cache all the rest
     $heros = Hero::all()->includes(array('SecretIdentity'))->toArray();
     $this->assertNotNull($heros[0]->SecretIdentity);
     // these should be from cache
     $queries = 0;
     $this->assertNotNull($heros[1]->SecretIdentity);
     $this->assertNotNull($heros[2]->SecretIdentity);
     $this->assertEquals(0, $queries, "this should have hit the cache");
 }
Exemple #3
0
 public function relationships()
 {
     return array('Hero' => Hero::hasOne('id', 'identityid'));
 }
Exemple #4
0
 public function relationships()
 {
     return array('Hero' => Hero::belongsTo('heroid', 'id'));
 }
Exemple #5
0
 public function testEmptyRelationshipsWithAllowEmpty()
 {
     $hero = new Hero(array('alias' => 'Spider Man'));
     $hero->save();
     $this->assertNull($hero->SecretIdentity);
 }
Exemple #6
0
 public function testJoiningAndFiltering()
 {
     $collection = Hero::all()->join(array('Powers', 'SecretIdentity'))->filter('SecretIdentity.realname = ?', "Peter Parker");
     $this->assertCount(1 * 2, $collection);
     $this->assertEquals("Spider Man", $collection[0]->alias);
 }