lithium\data\model\Query::paths PHP Method

paths() public method

Return the generated aliases mapped to their relation path
public paths ( Source $source = null ) : array
$source lithium\data\Source Instance of the data source to use for conversion.
return array Map between aliases and their corresponding dotted relation paths.
    public function paths(Source $source = null)
    {
        if ($source) {
            $this->applyStrategy($source);
        }
        return $this->_paths;
    }

Usage Example

Example #1
0
 public function testAliasAndPaths()
 {
     $model = 'lithium\\tests\\mocks\\data\\model\\MockQueryComment';
     $query = new Query(compact('model'));
     $this->assertIdentical('MockQueryComment', $query->alias());
     $this->assertIdentical('MockQueryComment', $query->alias(true));
     $this->assertIdentical('MockQueryComment2', $query->alias('MockQueryComment2'));
     $this->assertIdentical('MockQueryComment2', $query->alias());
     $this->assertIdentical('MockQueryComment2', $query->alias(true));
     $this->assertIdentical('MockQueryComment__2', $query->alias('MockQueryComment', 'Model1'));
     $this->assertIdentical('MockQueryComment2__2', $query->alias('MockQueryComment2', 'Model2'));
     $this->assertIdentical('MockQueryComment__2', $query->alias(true, 'Model1'));
     $this->assertIdentical('MockQueryComment2__2', $query->alias(true, 'Model2'));
     $query = new Query(compact('model') + array('source' => 'my_custom_table', 'alias' => 'MyCustomAlias'));
     $result = $query->export($this->db);
     $this->assertIdentical('{my_custom_table}', $result['source']);
     $this->assertIdentical('AS {MyCustomAlias}', $result['alias']);
     $this->assertIdentical('MyCustomAlias__2', $query->alias('MyCustomAlias', 'Relation1'));
     $this->assertIdentical('MyCustomAlias__3', $query->alias('MyCustomAlias', 'Other.Relation2'));
     $this->assertIdentical('MyCustomAlias2', $query->alias('MyCustomAlias2', 'Other.Other.Relation3'));
     $this->assertIdentical('MyCustomAlias', $query->alias());
     $this->assertIdentical('MyCustomAlias__2', $query->alias(true, 'Relation1'));
     $this->assertIdentical('MyCustomAlias__3', $query->alias(true, 'Other.Relation2'));
     $this->assertIdentical('MyCustomAlias2', $query->alias(true, 'Other.Other.Relation3'));
     $this->assertIdentical('Relation4', $query->alias(null, 'Relation4'));
     $this->assertIdentical('Relation5', $query->alias(null, 'Other.Relation5'));
     $this->assertIdentical('Relation5__2', $query->alias(null, 'Other.Other.Relation5'));
     $this->assertIdentical('Relation4', $query->alias(true, 'Relation4'));
     $this->assertIdentical('Relation5', $query->alias(true, 'Other.Relation5'));
     $this->assertIdentical('Relation5__2', $query->alias(true, 'Other.Other.Relation5'));
     $expected = array('MyCustomAlias' => null, 'MyCustomAlias__2' => 'Relation1', 'MyCustomAlias__3' => 'Other.Relation2', 'MyCustomAlias2' => 'Other.Other.Relation3', 'Relation4' => 'Relation4', 'Relation5' => 'Other.Relation5', 'Relation5__2' => 'Other.Other.Relation5');
     $this->assertEqual($expected, $query->paths($this->db));
     $model = 'lithium\\tests\\mocks\\data\\model\\MockQueryPost';
     $query = new Query(compact('model'));
     $query->alias(null, 'MockQueryComment');
     $query->alias('MockQueryPost2', 'MockQueryComment.MockQueryPost');
     $expected = array('MockQueryPost' => null, 'MockQueryComment' => 'MockQueryComment', 'MockQueryPost2' => 'MockQueryComment.MockQueryPost');
     $this->assertEqual($expected, $query->paths($this->db));
 }
All Usage Examples Of lithium\data\model\Query::paths