![]() I searched for a replacement gem for union in ActiveRecord and suprisingly didn’t find anything recent that fit the bill except one. Before we write our own solution, what about any gems? What about a gem? ![]() Of complexity that is unnecessary due to its potentially shifting api. Some of the best solutions are clear, explicit code that is straightforward. There are a lot of other Arel table solutions out there (many of which work) but I wanted to keep my solution high-level and for lack of better It is going to stick around for some time. You can’t depend on library features where you don’t control that library unless To only use the public api for exactly this reason. A rule I follow while adding code on top of a gem or third-party library, is The current solution unworkable for union queries. Unfortunately, the features it was using became a private method rendering The application had relied onĪ custom method that dug deeply into Arel Tables (bind_keys I believe). In this case it was an upgrade to a newer version of Rails. ![]() Recently, I did run into a roadblock with Active Record. Moving onto Arel tables next… Can we use Arel tables? For more information see my older post on the topic. This means no ActiveRecord chaining or helper methods work on the result. to_a on the result as otherwise you can’t work with it. There are some downsides to this approach. to_a #=> Collection of users from the union query ![]() execute ( "SELECT users.* FROM users WHERE users.active = 't' UNION SELECT users.* FROM users WHERE users.manager = 't'" ) result. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |