Hi, I have some issues with Phalcon query builder, issues are critical and I've tried many times to find a logical solution for them, but nothing.
First Issue
I think this is a bug! however...
I want get a column name like title
as foo.title
, look at sample code:
$options = ['...'];
$builder = $this->modelsManager->createBuilder();
$builder->from(['aircrafts' => 'App\Models\Aircrafts']);
$modelAlias = 'aircrafts';
$columns = [];
if($options['columns']) {
foreach( $options['columns'] as $column ){
columns[] = $column . ' as `' . $modelAlias . '.' . $column . '`';
}
}
# sample query
# SELECT id as `aircrafts.id`, title as `aircrafts.title` FROM ...
Ok, as you know in mysql this query is valid, but seems phalcon does not offer any way to do this.
Backticks (`) in phalcon query builder cause query scan error, how could use dot (.) in phalcon columns name?
Second Issue
Query builder resultset issue
Sample code:
$builder = $this->modelsManager->createBuilder();
$builder->from(['seatmap' => 'App\Models\SeatMaps']);
$builder->join('App\Models\Aircrafts', null, 'aircrafts');
$builder->join('App\Models\Airlines', 'aircraft.airline = airline.id', 'airline');
// Set columns
$builder->columns('seatmap.*, aircrafts.*, airline.title');
// ...Execute Query...
query result will be something like:
// Complex Resultset
[
'seatmaps' => {
'id': '...',
'title' : '...',
// ..
},
'aircrafts' => {
'id': '...',
'title' : '...',
// ...
},
'title' => '...' // this is airline title
]
as you see, in this case I need title
column from airlines table and all columns from seatmaps (seatmaps.*)
and aircrafts (aircrafts.*)
models. how its possible to get data in following format:
// Complex Resultset
[
'seatmap' => {
'id': '...',
'title' : '...',
//...
},
'aircrafts' => {
'id': '...',
'title' : '...',
//...
},
// title belongs to airlines, so i want it be a child of airlines object
'airlines' => {
'title' => '...'
}
]
how can I do this, fetch all columns in their related object in query builder resultset?