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; }
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"); }
public function relationships() { return array('Hero' => Hero::hasOne('id', 'identityid')); }
public function relationships() { return array('Hero' => Hero::belongsTo('heroid', 'id')); }
public function testEmptyRelationshipsWithAllowEmpty() { $hero = new Hero(array('alias' => 'Spider Man')); $hero->save(); $this->assertNull($hero->SecretIdentity); }
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); }