Chained associated against pg_scope and regular scope fail #243
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR only adds failing tests for now. (New PR based of master in comparison to #241)
Looks like the error has the same symptoms like #235 but a different cause ... here it seems to be the automatic table aliasing done by rails. Let me explain.
If you simply do
Person.joins(:houses).to_sql
, everything is fine:But if you introduce a second join to the same table, even by a string option, it automatically aliases the first join. (the following query is invalid sql but shows what rails does):
Interesting thing is, that if you change the join string to
INNER JOI ...
(so only remove theN
fromJOIN
) or remove the lastN
("INNER JOIN \"with_model_houses_41998\" O
), no alias is created:The problem lies in the fact that this table aliasing is also done when the join is happening in a subquery:
I'm not sure, but this sub query should not change the outer query and the table aliasing done by rails is unnecessary (or not?).
A solution on the
pg_search
side is simply to do table aliasing in the subquery by itself:But this means the join must be done by hand in association.rb or at least I do not know any way to specify a table alias manually in
.joins()
.So main question are:
pg_search
set a table alias manually in the subquery join to stop automatic table aliasing?