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"); }