New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
as_json works differently for preload and eagerload #24314
Comments
@salmanasiddiqui I did not get the use of |
I just wanted to show that |
Hi @salmanasiddiqui this isn't documented, but a known limitation. Going to mark this as a documentation issue. |
Known limitation, u mean that this cant be fixed and there isnt any workaround aswell? I don't think that documenting it, is enough. It should also log a warning that select is being ignored in such scenarios. |
This isn't even a limitation. This is the expected behavior. When you put an additional field in the select column, it is accessible through the record. I don't think this warrants a mention explicitly on |
@sgrif the issue is that select isn't returning extra selected values in case of eager load. |
Ah, I see now. It's a very confusingly set up report... |
workaround for anyone else facing this issue replace example: |
Looks like it, yes. |
In order to work around rails/rails#24314 et al
… eager loading causing it to ignore custom select clauses. [ci skip] Fixes rails#24314
Steps to reproduce
Expected behavior
@tickets.first.as_json
should be equal to@tickets.references(:portfolios).first.as_json
Actual behavior
@tickets.first.as_json
includes the code (alias column defined in theselect
)@tickets.references(:portfolios).first.as_json
does not include the code (alias column defined in theselect
)Note
The problem arises only when
eager_load
is called byincludes
,preload
works fine. More to that, usingjoins
works fine aswell.System configuration
Rails version: 4.2.6
Ruby version: 2.1.8
The text was updated successfully, but these errors were encountered: