Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
This gem, abstracted out from Thinking Sphinx, turns a bunch of association trees from the perspective of a single model and builds a bunch of OUTER JOINs that can be passed into ActiveRecord::Relation's join
method. You can also find out the generated table aliases for each join, in case you're referring to columns from those joins at some other point.
If this gem is used by anyone other than myself/Thinking Sphinx, I'll be surprised. My reason for pulling it out is so I can more cleanly support Rails' changing approaches to join generation (see v3.1-v4.0 compared to v4.1-v5.1 compared to v5.2).
It's a gem - so you can either install it yourself, or add it to the appropriate Gemfile or gemspec.
gem install joiner --version 0.6.0
First, create a join collection, based on an ActiveRecord model:
joiner = Joiner::Joins.new User
Then you can add joins for a given association path. For example, if User has many articles, and articles have many comments:
joiner.add_join_to [:articles]
joiner.add_join_to [:articles, :comments]
If you need the table/join alias for a given association path, just ask for it:
joiner.alias_for([:articles, :comments])
And once you've loaded up all the joins, you'll want something you can push out into ActiveRecord::Relation#joins
:
User.joins(joiner.join_values)
You can also check if a given association path will return potentially more than one record (thus perhaps requiring aggregation), or find out what the model at the end of the path is:
path = Joiner::Path.new(User, [:articles, :comments])
path.aggregate? #=> true
path.model #=> Comment
Please note that this project now has a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)Copyright (c) 2013-2020, Joiner is developed and maintained by Pat Allan, and is released under the open MIT Licence.
FAQs
Unknown package
We found that joiner 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
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.