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

Scopes don't work with subclasses #1

Closed
jafuentest opened this issue Jul 27, 2018 · 2 comments
Closed

Scopes don't work with subclasses #1

jafuentest opened this issue Jul 27, 2018 · 2 comments
Labels
bug Something isn't working

Comments

@jafuentest
Copy link
Contributor

Steps to reproduce:

Define the following classes:

class Transport
  include Mongoid::Document
  include MongoidEnumerable

  enumerable :terrain, %w[land water]
end

class Car < Transport; end

class Boat < Transport; end

Now, running:

Car.all gives the following criteria

 => #<Mongoid::Criteria
  selector: {}
  options:  {}
  class:    Car
  embedded: false>

Car.land gives the following criteria

 => #<Mongoid::Criteria
  selector: {"terrain"=>"land"}
  options:  {}
  class:    Transport
  embedded: false>

Notice how Car.land sets the selector {"terrain"=>"land"} correctly, but sets the class to the superclass Transport, so Car.land will give you all Vehicles of land terrain instead of just cars with land terrain

I'll try to see if I can fix it myself and send you a PR

douglaslise added a commit that referenced this issue Jul 28, 2018
@douglaslise
Copy link
Owner

Thank you very much @jafuentest by the fix. Be welcome to contribute here.

@douglaslise
Copy link
Owner

Closed by pull request #2

@douglaslise douglaslise reopened this Jul 28, 2018
@douglaslise douglaslise added the bug Something isn't working label Jul 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants