
Security News
MCP Community Begins Work on Official MCP Metaregistry
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
rails_select_on_includes
Advanced tools
Selected virtual attributes will be now typecasted as usual attributes
#Rails version Supports rails 4.x and rails 5-5.1.4, 5.1.5, and 5.2.0.rc1 now!
Master is now runs on rails 5.2, rails_5.1.4 branch is for rails less than 5.1.5, rails_4 branch is for rails 4 support
This gem solves issue in rails: https://github.com/rails/rails/issues/15185 for base_class.
It was impossible to select virtual attributes to object from its relations or any other way when using includes and where ( actually when includes becomes eager_load, i.e. when you add not SOME_CONDITION, but SOME_CONDITION_ON_INCLUDES, http://blog.bigbinary.com/2013/07/01/preload-vs-eager-load-vs-joins-vs-includes.html ).
Example from upper rails issue:
post = Post.includes(:comments).select("posts.*, 1 as testval").where( SOME_CONDITION ).first
post.testval # Undefined method!
This gem solves problem for base class i.e.
post = Post.includes(:comments).select("posts.*, 1 as testval").where( SOME_CONDITION ).first
post.testval # 1
but of course it doesn't include virtual attributes in included relations
post = Post.includes(:comments).select("posts.*, 1 as testval").where( SOME_CONDITION ).first
post.comments.first.testval # Undefined method!
Данный gem решает проблему в рельсах с виртуальными аттрибутами при использовании includes, когда рельсы собирают в запрос в joins с алиасами на все аттрибуты. В настоящий момент в модель не собираются никаким боком виртуальные аттрибуты ( имеется ввиду когда includes ведет себя как eager_load и создает сложный одинарный запрос, подробнее: http://blog.bigbinary.com/2013/07/01/preload-vs-eager-load-vs-joins-vs-includes.html ).
В частности проблема описана здесь: https://github.com/rails/rails/issues/15185
В коде примера по ссылке выше это выглядит так:
post = Post.includes(:comments).select("posts.*, 1 as testval").where( SOME_CONDITION ).first
post.testval # Undefined method!
Данный gem решает эту проблему для базового класса, т.е.:
post = Post.includes(:comments).select("posts.*, 1 as testval").where( SOME_CONDITION ).first
post.testval # 1
Но это не касается, объектов попадающих под инклюд:
post = Post.includes(:comments).select("posts.*, 1 as testval").where( SOME_CONDITION ).first
post.comments.first.testval # Undefined method!
Add this line to your application's Gemfile:
#rails 6
gem 'rails_select_on_includes', '~> 6.0.0'
#rails 4
gem 'rails_select_on_includes', '~> 0.4.11'
#rails 5.1.4
gem 'rails_select_on_includes', '~> 5.1.4.0'
#rails 5.1.5
gem 'rails_select_on_includes', '~> 5.1.5.0'
#rails 5.2
gem 'rails_select_on_includes', '~> 5.2.1'
And then execute:
$ bundle
Or install it yourself as:
$ gem install rails_select_on_includes
Works out of the box, monkey-patches base-class alias columns, for select attributes, and JoinBase with JoinDependency to proper typecasting.
It not affecting query creation, since query already contains all columns, i.e. to_sql returns same string. Works with selection in all formats:
Работает из коробки, нежно манки-патча алиасы прямо перед инстанцированием коллекции, а так же не менее нежно JoinBase и JoinDependency :), чтобы полученные аттрибуты были приличных типов, а не только строк, не влияет на создаваемый запрос в БД т.е to_sql не меняется.
Поддерживает select в следующих форматах :
rake test
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rails_select_on_includes.
The gem is available as open source under the terms of the MIT License.
FAQs
Unknown package
We found that rails_select_on_includes demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
Research
Security News
Socket uncovers an npm Trojan stealing crypto wallets and BullX credentials via obfuscated code and Telegram exfiltration.
Research
Security News
Malicious npm packages posing as developer tools target macOS Cursor IDE users, stealing credentials and modifying files to gain persistent backdoor access.