Posted 29 days ago. Visible to the public. Repeats.

Shortcut for getting ids for an ActiveRecord scope

You can use .ids on an ActiveRecord 4+ scope to pluck all the ids of the relation

Copy
User.where("users.name LIKE 'Foo Bar'").ids # same as User.where("users.name LIKE 'Foo Bar'").pluck(:id)
Growing Rails Applications in Practice
Check out our new e-book:
Learn to structure large Ruby on Rails codebases with the tools you already know and love.

Owner of this card:

Avatar
Martin Schaflitzl
Last edit:
25 days ago
by Besprechungs-PC
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Martin Schaflitzl to makandra dev
This website uses cookies to improve usability and analyze traffic.
Accept or learn more