Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add :compose option to has_many #28626

Closed
wants to merge 1 commit into from

Conversation

Bahanix
Copy link
Contributor

@Bahanix Bahanix commented Mar 31, 2017

Summary

Generates additionnal has_many for each given association scope.

# Before
has_many :posts
has_many :published_posts, -> { published }, class_name: "Post"

# After
has_many :posts, compose: :published

Other Information

In my rails projects, I write a lot of has_many variations to be able to use fine-grained preload. Eg: Author.all.preload(:published_post)…. So I wrote this feature to have syntaxic sugar to shorten all theses has_many.

Here is an unpublished post I wrote about this feature:

https://medium.com/octoly-tech/activerecord-has-many-compose-option-4f2cbdb524a3

Perhaps a better name for this option may be preloadable_scopes—it does not cover all things one can do with this feature, but it is a quite self-explained option name since preloading theses generated has_many would be (I think) its main usage. I am not a native english and this is my first contribution, do not hesitate suggesting other option names.

Generates additionnal has_many for each given association scope.

    # Before
    has_many :posts
    has_many :published_posts, -> { published }, class_name: "Post"

    # After
    has_many :posts, compose: :published
@rails-bot
Copy link

rails-bot bot commented Dec 18, 2019

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Thank you for your contributions.

@rails-bot rails-bot bot added the stale label Dec 18, 2019
@rails-bot rails-bot bot closed this Dec 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants