Skip to content

Support querying through a hasMany relation #63

Closed
@techniq

Description

@techniq

Version 0.11.9 provided the ability to perform a WHERE EXISTS query when referencing a hasMany property, but currently if you try to query deeper, it's applying the JOIN to the main SELECT and not the subselect within the WHERE EXISTS

/api/v1/races?where={"events.event_category.name":{"==":"5k"}}

Current

select `race`.* from `race`
inner join `event_category` on `event`.`event_category_id` = `event_category`.`id`
where exists (
  select `event`.* from `event` where `event_category` = '5k' and `event`.`race_id`=`race`.`id`
)
 - ER_BAD_FIELD_ERROR: Unknown column 'event_category' in 'where clause'

Should produce

select `race`.* from `race`
where exists (
  select `event`.* from `event`
  inner join `event_category` on `event`.`event_category_id` = `event_category`.`id`
  where `event_category` = '5k' and `event`.`race_id`=`race`.`id`
)

It looks to be an issue with closure within processRelationField. I believe the query will need to be passed in explicitly

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