Skip to content

Crash on Inspector with belongs-to relation #147

Description

@smeeckaert

When using an Inspector with a custom query using a belongs-to relation the controller will create a query using wrong aliases resulting in a crash.

Config example:

return array(
    'model' => 'Model_With_BelongsTo',
    'query' => array(
        'model'    => 'Model_With_BelongsTo',
       'related' => array('relation'),
        'callback' => function ($query) {
                return $query->where('relation.field', 1);
            }

    ),
    'input' => array(
        'key' => 'id',
    )
);

Will create something similar to

SELECT COUNT(DISTINCT `t0`.`id`) AS count_result,
`t1`.`id` AS `t1_c0`,`t1`.`other_fields_from_t0` AS `t1_c1`,
`t1`.`t1_real_fields` as `t1_c2`
FROM `table_0` AS `t0`
LEFT JOIN `table_2` AS `t1` ON (`t0`.`rel_id` = `t1`.`id`)
WHERE `t0`.`id` = 1

The where is executed on the wrong table and half the fields are selected on the wrong alias too.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions