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
Error using default_scope on subclass model #113
Comments
Hi Mikael :) The exception should have read I can implement the default scope feature for subclasses. class Thing
include NoBrainer::Document
default_scope { where(:visible => true) }
end
class Subthing < Thing
include NoBrainer::Document
default_scope { order_by(:id) }
end
Are you on board with this behavior? Note: the default scope of any model is |
Hi Nicolas! Thanks. That sounds like what I think I'd expect. Multiple default scopes in a single class could be useful, I suppose, and perhaps simplifies the implementation? I can imagine someone wanting to use the subclass default scope to override the parent default scope, but maybe that can be done with something like: class Subthing < Thing
include NoBrainer::Document
default_scope { unscoped.order_by(:name) }
end Re: the default ID order, that's good to know, but it was just an example. :) |
you wouldn't be able to override the parent default scope. So we have three possible behaviors:
I don't think we should do 2) because of potential security issues: If a parent class has some So I think I'll do 1) -- If you want to override the parent default scope, well, It probably means that you are not using subclasses properly, since the subclass would not share the same behavior as its parent. |
That sounds reasonable to me! |
All done :) |
Wow, excellent! Thank you very much. |
Hello. I'm trying to port the test app for rails_admin to use NoBrainer, and ran across an issue with using
default_scope
in a model that's a subclass in a polymorphic hierarchy.Here is a gist with a minimal example.
The exception is generated from this line. This precondition seems to be copied from another method. Is it perhaps there by mistake? Or are there actual problems with using default scopes on subclasses?
The text was updated successfully, but these errors were encountered: