-
Notifications
You must be signed in to change notification settings - Fork 162
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
Convert active record queries to ARel #416
base: master
Are you sure you want to change the base?
Convert active record queries to ARel #416
Conversation
@thom-oman can you please check this PR? |
@@ -47,8 +47,20 @@ def included(base) | |||
query_builder.most_recent_transition_join |
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.
Slight outside of the diff but can we ensure that this method hasn't changed, from memory this is covered by tests though
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.
@thom-oman Do you mean it should return SQL string? Arel is more powerful, but I understand your point. Do you have any idea how we can return non-sql version as well, to make it possible to change via arel public methods?
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.
Lets decide whether you want to use SQL string everywhere or arel in some cases.
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.
My concern is that it'll be a breaking change for those expecting this method to return a string. One approach would be to have an optional parameter that returns arel, but defaults to string. Not sold on that idea though haha.
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.
Another solution is to add breaking change to the CHANGELOG. I think in 95% of the cases it will still work with arel, as those objects are still usable in where
, having
and joins
. I don't think anyone concatenated string of a JOIN
.
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.
Yeah I don't think it will be a concern for many, I can't think of many uses but I'm just thinking of Hyrums laws and that not everyone checks the change log before bumping gems.
Also I just checked and this would break something in the GoCardless API, only one instance but you can assume it would break for others. Hence we should avoid making this a breaking change, don't think this justifies a major bump either.
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.
ARel considered as private interface for activerecord, so I don't think it should be publicly accessible by the Hyrums law. Going to make it to return SQL with a .to_sql
call, so it will not to brake anyone code. Rebased with push force.
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.
hey @dmitry sorry for the delay, not been able to dedicate much time to Statesman! This looks great, thanks for opening a PR. First thing, can we fix the Rubocop errors so that we can see that the tests pass (I need to fix this if I can find the time), my Arel isn't that great. One small concern I have is adding in_state_conditions
that returns Arel to the public interface, though I'm undecided how strongly I feel that.
@thom-oman tried to fix as many rubocop as I can. Regarding the |
2d89275
to
da1be70
Compare
da1be70
to
4f04c2f
Compare
@thom-oman just let me know what should I do for the next steps. |
hey @dmitry sorry again for the slow responses, not been able to dedicate much time to this. There are still a few rubocop issues that prevent us from seeing how the tests are looking. Though right now, I can't see any behaviour change. The proposed benefit is to allow the join transitions to use arel and the flexibility that brings. Would you be able to show how this would be used from the developer side? I think you mean that I also don't think we should consider arel a private interface of Rails since Statesman is calling it directly and I think many people still use it when it makes more sense vs AR. Does this make sense? |
With this change it will be possible to use
JOIN
s andWHERE
s separately in custom SQLs, and it will allow to changemost_recent_
prefix in real time, rather than fixing with static name on a class level.