Skip to content

Add support for special cases when ActiveRecord creates aliased joins #82

@antillas21

Description

@antillas21

A very interesting case was recently brought to our attention, see this gist: https://gist.github.com/antillas21/4e22f87888ea9114025c

A quick overview:

  • There is an Individual model that is related to an (insurance) Coverage model on two different roles: Insured (I suppose the intention is to be a beneficiary) and as a Payer.

  • Developer wanted to display a datatable that included both the insured person data (name, address) and the payer data (same columns: name and address).

  • ActiveRecord was creating an aliased join on individuals like this:

    LEFT OUTER JOIN "individuals" ON "individuals"."id" = "coverages"."insured_id" LEFT OUTER JOIN "individuals" "payers_coverages" ON "payers_coverages"."id" = "coverages"."payer_id"
    

    first join is to address the insured data and a second time (aliased) to address the payer data.

Proposed solution:

  • rework the search_condition (and related methods) to address the case when we need to pass aliased table joins to search by.
  • currently, search_condition delegates to new_search_condition or deprecated_search_condition to actually build a search query that will be concatenated... please also rework this mess.

Proposed behavior:

  • search_condition method must return a search query (in Arel) that will be concatenated.
  • if this method receives a column from an existent model table, work as it currently does.
  • if this method receives a column, from an aliased table join, build a specific query without relying on discovering a non-existent model arel table.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions