Sunday, March 3, 2019

reselect, negative enum scopes and more!

Posted by imtayadeway

Why hello there! Tim here bringing you all the latest and greatest from This Week In Rails.

Negative scopes for enum values

Some sugar around enum values allows you to make negative scopes such as

Post.not_drafted # => where.not(status: :drafted)

New method: reselect

Allows you to change a previously set select statement in the same manner to rewhere and reorder, e.g.

Post.select(:title, :body).reselect(:created_at)

#size fixed when using SELECT DISTINCT

#size_ would ignore the DISTINCT in the select, giving a different result to #count. This is now fixed!

Active Storage’s _blob loading fixed

If you attached a has_one_attachment attachment, you may have found that the attachment’s _blob method would have returned nil. This was fixed by assigning the blob when the attachment is assigned.

22 people contributed to Rails since our last issue; you can see the full list of changes here.

Until next week!