You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this is a real issue or not but this changes the behaviour of + on SQL literals. This is a very convoluted example but I used to do stuff like sql('CASE WHEN ') + COALESCE(foo, bar).to_sql + sql(' ELSE baz END') and this started complaining with unsupported: String. I've now realised that if you're finishing with a bunch of concatenated strings and SQL literals then you can just stick to strings entirely like 'CASE WHEN ' + COALESCE(foo, bar).to_sql + ' ELSE baz END'. That's not a problem but I'm wondering whether there are other legitimate uses for +. The method is actually derived from the String class and there are no aliases that you can use instead.
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I actually confused two issues slightly. The unsupported: String error went away after wrapping the to_sql stuff in sql(). The + issue resulted in + actually appearing in the final SQL string.
As I said, I realised that my code was overly complicated anyway but a dedicated node could still be useful so I'll try to come up with a PR when I have a moment. Things are a bit heavy this week.
cf7d7d0
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'm not sure if this is a real issue or not but this changes the behaviour of
+
on SQL literals. This is a very convoluted example but I used to do stuff likesql('CASE WHEN ') + COALESCE(foo, bar).to_sql + sql(' ELSE baz END')
and this started complaining withunsupported: String
. I've now realised that if you're finishing with a bunch of concatenated strings and SQL literals then you can just stick to strings entirely like'CASE WHEN ' + COALESCE(foo, bar).to_sql + ' ELSE baz END'
. That's not a problem but I'm wondering whether there are other legitimate uses for+
. The method is actually derived from the String class and there are no aliases that you can use instead.cf7d7d0
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, that's an interesting point. If you'd like to send a PR, we could have a dedicated node for SQL literal, and change the case expression here:
baby_squeel/lib/baby_squeel/nodes.rb
Line 20 in b97fa0e
cf7d7d0
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.
Sorry, I actually confused two issues slightly. The
unsupported: String
error went away after wrapping theto_sql
stuff insql()
. The+
issue resulted in+
actually appearing in the final SQL string.As I said, I realised that my code was overly complicated anyway but a dedicated node could still be useful so I'll try to come up with a PR when I have a moment. Things are a bit heavy this week.