-
Notifications
You must be signed in to change notification settings - Fork 228
Closed
Labels
Milestone
Description
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 aPayer
. -
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 onindividuals
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 thepayer
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 tonew_search_condition
ordeprecated_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 (inArel
) 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.