-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG]: PHQL; Undefined index: ... in phalcon/Mvc/Model/Resultset/Complex.zep #14657
Comments
Let's investigate this bug in the current sprint. If we can fix it easily in Zephir we do it in 4.0.x if work is required in the PHQL parser we move this to 4.1.x |
I just spent 5 hours on this and not getting close to finding it. From previous iterations of this bug such as #14488 (because they are related) I found that there was a change made to the columnMap and how aliases are calculated ( For the above example we could access
i.e. the results would come in ignoring the
If we remove the
|
Honestly it will be easier to tell people that if you declare an alias, then it will prefix your fields (in the docs) but I am not 100% sure that this is the case and I have not been able to find the commit (or the place in the code) that does this.... |
Let's add the comment to our docs for now. We can close this or keep it open and move it to 4.1 and have a fresh look at this when we look at the PHQL fixes as well. |
But how about legacy applications? If this behavior becomes a BC-break, a ton of code should be rewritten. |
@sergeyklay Can you shine your light on this one? |
I'll try to sort out |
This also crashes Phalcon\Mvc\Model\Query\Builder result set, for example:
|
Btw, there is a typo in the SQL (ambiguous column name: SELECT
o.obj_name,
- obj_type,
+ o.obj_type,
od.*
FROM
Objects AS o
LEFT JOIN ObjectDetails AS od ON
od.obj_id = o.obj_id
WHERE
o.obj_id = 1 |
Found the bad commit using git bisect: e851f48 (#13663) Code to reproduce: use Phalcon\Db\Adapter\Pdo\Sqlite;
use Phalcon\Di;
use Phalcon\Di\FactoryDefault;
use Phalcon\Mvc\Application;
use Phalcon\Mvc\Model;
Di::setDefault($container = new FactoryDefault());
$container->setShared(
'db',
new Sqlite(
['dbname' => '/tmp/test.sqlite']
)
);
class Objects extends Model
{
public $obj_id;
public $obj_name;
public $obj_type;
}
class ObjectDetails extends Model
{
public $obj_id;
public $details;
}
$app = new Application($container);
$sql = <<<EOF
SELECT
o.obj_name,
o.obj_type,
od.*
FROM
Objects AS o
LEFT JOIN ObjectDetails AS od ON
od.obj_id = o.obj_id
WHERE
o.obj_id = :obj_id:
EOF;
/** @var \Phalcon\Mvc\Model\Query $query */
$query = $app->modelsManager->createQuery($sql);
print_r(explode(',', $query->getSql()['sql'])); Commit e851f48 introduces the following changes: Array
(
+ [0] => SELECT "o"."obj_name" AS "o_obj_name"
- [0] => SELECT "o"."obj_name" AS "obj_name"
+ [1] => "o"."obj_type" AS "o_obj_type"
- [1] => "o"."obj_type" AS "obj_type"
[2] => "od"."obj_id" AS "_od_obj_id"
[3] => "od"."details" AS "_od_details"
[4] => "od"."obj_type" AS "_od_obj_type" FROM "objects" AS "o" LEFT JOIN "object_details" AS "od" ON "od"."obj_id" = "o"."obj_id" WHERE "o"."obj_id" = :obj_id
) |
See: - #14657 - #13663 /cc @CameronHall
Fixed in the |
See: - #14657 - #13663 /cc @CameronHall
See: - #14657 - #13663 /cc @CameronHall
Describe the bug
Can't run PHQL query when selecting columns from a table with asterisk, and specific table aliased columns from some other table. No problem in v3.4.5.
Might be related to #14488.
To Reproduce
Expected behavior
To be able to run the query and access the table aliased columns.
Details
The text was updated successfully, but these errors were encountered: