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

Scoping the Find Example #54

Closed
mzaragoza opened this issue Jun 6, 2015 · 3 comments
Closed

Scoping the Find Example #54

mzaragoza opened this issue Jun 6, 2015 · 3 comments

Comments

@mzaragoza
Copy link

Scoping the Find

All ByStar methods (except oldest, newest, previous, next) return ActiveRecord::Relation and/or Mongoid::Criteria objects, which can be daisy-chained with other scopes/finder methods:

Post.by_month.your_scope
Post.by_month(1).include(:tags).where("tags.name" => "ruby")

I was wondering how to do the reverse
Tag.include(:posts). # WHERE Post.by_month('May')

@johnnyshields
Copy link
Collaborator

How about:

Tag.posts.by_month('May')

@mzaragoza
Copy link
Author

I really need the Tag.include(:posts)

@johnnyshields
Copy link
Collaborator

This is a question for ActiveRecord, not this gem specifically. All this gem does is making a query scopes. In other words:

Tag.include(:posts). # WHERE Post.by_month('May')

is equivalent to:

Tag.include(:posts). # WHERE Post.where name = "foobar"

Hence closing this issue. Please ask on stackoverflow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants