-
Notifications
You must be signed in to change notification settings - Fork 2
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
Fix a bug where virtual attribute are included when aliasing joined table column names #28
base: master
Are you sure you want to change the base?
Conversation
e36c4e0
to
0757f78
Compare
Seems fine based on everything you mentioned at standup - removing the names of the virtual attributes from the list of columns for the model sounds exactly like the sort of solution we need. That said, I doubt I'd have the context to understand the fix if I was looking at this PR tomorrow or next week 'cos by then I'll have forgotten the details of our standup discussion. To help future investigators can we include some more details of what the problem is and how it manifests itself in the commit message or PR description. I think you mentioned that it's a bug with rails 4.x attribute API that was fixed in rails 5.x, so it would be great to include a link to that fix too if we can. |
0757f78
to
d7e4bd7
Compare
…able column names
d7e4bd7
to
78acc92
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I echo @h-lame's notes that a reference to the relevant bug/PR/issue in Rails would good, other than that the PR LGTM.
P.S. 💯 for CreateProblems
migration 😆
I've updated the PR description with a proper explanation of the issue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 on the new description; it's much clearer what's going on and will really help us if we need to come back to this.
b10fb95
to
b065151
Compare
Would it make sense to only include these fixes in AR 4.2? E.g put a I know we have the guard on the presence of |
b065151
to
a04cf4a
Compare
@h-lame I've addressed your comment even though it will still work with AR 5+. The |
@elenatanasoiu please 👀 |
Issue
ActiveRecord 4.2 includes virtual attributes in selects with joins. This raises an error because virtual attributes are not persisted and there's no column with the name to the virtual attribute.
Background:
ActiveRecord 4.2 uses a slightly different implementation of Attributes API than in 5.0+. Before ActiveRecord 5, this API was considered private (although technically it wan't). In ActiveRecord 5+, the issue was fixed (by accident) because of the significant refactoring that took place in ActiveRecord and ActiveModel.
Some of the issues with virtual attributes in AR 4.2 were fixed with the addition of a new property called
persistable_attribute_names
. rails/rails@5383f22bb83 When checking for dirty attributes for example, they use that instead together with changed model attributes (which include the virtual ones as well).Proposed Solution
For now we can override the
column_names
method ofJoinPart
, which theJoinDependency
uses to generate aliases for the joined tables.@FundingCircle/gdpr-engineering 👀