public function testEmptyRelationshipsWithoutAllowEmpty() { $power = new Power(array('description' => 'Spider Senses')); $power->save(); $this->setExpectedException('\\Pheasant\\Exception'); $foo = $power->Hero; }
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 testNestedJoiningAndFiltering() { $collection = Power::all()->join(array('Hero' => array('SecretIdentity' => array('Hero h2'))))->filter('SecretIdentity.realname = ?', "Peter Parker"); $this->assertCount(2, $collection); $this->assertEquals('Super-human Strength', $collection[0]->description); $this->assertEquals('Spider Senses', $collection[1]->description); }
public function testNestedIncludesHitsCache() { $queries = 0; $this->connection()->filterChain()->onQuery(function ($sql) use(&$queries) { ++$queries; return $sql; }); // the first lookup of SecretIdentity should cache all the rest $powers = Power::all()->includes(array('Hero' => array('SecretIdentity')))->toArray(); $this->assertNotNull($powers[0]->Hero->SecretIdentity); // these should be from cache $queries = 0; foreach ($powers as $power) { $this->assertNotNull($power->Hero->SecretIdentity); } $this->assertEquals(0, $queries, "this should have hit the cache"); }