-
-
Notifications
You must be signed in to change notification settings - Fork 807
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
Mongoid 4.0 support #407
Mongoid 4.0 support #407
Conversation
@Zhomart sorry for replying so slowly and thanks for the PR. This is impressive. Will review soon. |
I've created demo app http://ransack-mongodb-demo.herokuapp.com/ |
I've successfully implemented some basic searching into my app using some simple field_cont and collection select search filters. Worked flawlessly for me. |
Thanks, guys. |
Hi, Does it support search by embedded document? class Band
include Mongoid::Document
embeds_one :label
end
class Label
include Mongoid::Document
field :name, type: String
embedded_in :band
end Can I find band with specific label.name? |
No, this patch was quick solution. But I will add it if I have time. |
@jonatack Is anything else blocking the merge of this PR. Anything we can help with? |
@maran just a question of time (there are many changes to review in this PR), and getting some urgent regressions in Ransack fixed first and improving the gem's test coverage, because missing tests were the reason why the regression occured. This looks like an interesting PR that is super worthy, and I'm not against merging it in if it doesn't degrade Ransack performance too much and won't be too difficult to maintain. |
* master: Patch Rails commit c1a118a Remove extra space [skip ci] Use newer Ruby hash syntax [skip ci] Update change log [skip ci] Wrap 80 characters [skip ci]
@Zhomart I just gave a try with mongoid 4 a simple query on Category.search(:_id_in => ['544d26a44d61630b5c070000']).result
=> #<Mongoid::Criteria
selector: {}
options: {}
class: Category
embedded: false>
Category.search(:_id_in => ['544d26a44d61630b5c070000']).result
=> #<Mongoid::Criteria
selector: {}
options: {}
class: Category
embedded: false>
Category.search(:id_in => ['544d26a44d61630b5c070000']).result
D, [2014-11-02T17:35:41.787651 #12628] DEBUG -- : MOPED: 127.0.0.1:27017 COMMAND database=food_development command={:count=>"categories", :query=>{}} runtime: 0.4760ms
D, [2014-11-02T17:35:41.788500 #12628] DEBUG -- : MOPED: 127.0.0.1:27017 COMMAND database=food_development command={:count=>"categories", :query=>{}} runtime: 0.3480ms
NoMethodError: undefined method `type' for nil:NilClass Tested with a field name it works : irb(main):041:0> Category.search(:name_in => 'Foo').result
D, [2014-11-02T17:37:14.124320 #12628] DEBUG -- : MOPED: 127.0.0.1:27017 COMMAND database=food_development command={:count=>"categories", :query=>{}} runtime: 0.3820ms
D, [2014-11-02T17:37:14.125242 #12628] DEBUG -- : MOPED: 127.0.0.1:27017 COMMAND database=food_development command={:count=>"categories", :query=>{}} runtime: 0.3090ms
D, [2014-11-02T17:37:14.126129 #12628] DEBUG -- : MOPED: 127.0.0.1:27017 COMMAND database=food_development command={:count=>"categories", :query=>{}} runtime: 0.3080ms
D, [2014-11-02T17:37:14.126711 #12628] DEBUG -- : MOPED: 127.0.0.1:27017 COMMAND database=food_development command={:count=>"categories", :query=>{}} runtime: 0.2330ms
D, [2014-11-02T17:37:14.127326 #12628] DEBUG -- : MOPED: 127.0.0.1:27017 COMMAND database=food_development command={:count=>"categories", :query=>{}} runtime: 0.2370ms
=> #<Mongoid::Criteria
selector: {"name"=>{"$in"=>["Foo"]}}
options: {}
class: Category
embedded: false> |
@sbounmy, it must work now. |
thanks a lot @Zhomart , can't wait to get this merged |
Let's give this a shot. @Zhomart, thank you for your persistence with this feature. Before releasing it in a new version of Ransack, could you update the documentation (README, wiki) where needed, and the change log? Everyone, please try using Ransack master and let us know if any issues. |
Thanks for implementing Mongoid support... I am finding some issues
I'll get into the code and see if I can contribute! |
@vanboom thanks for the feedback, this is exactly what we need before releasing this feature in the official gem. Any contributions would be great! |
Suggestion: make dynamic fields searchable. If I return the name of my dynamic fields from ransackable_attributes, it works... is there an option to allow all fields to pass? vs. having to specify the dynamic fields individually (which is not possible) I think having a way to pass all fields will enable Ransack searches for dynamic fields...which would be pretty darn cool imho. Thanks - sorry I haven't been able to figure this one out yet... |
Mongoid stores its relational and embedded attributes in class arrays, I wonder if we can take advantage of that somehow ... And if the only blocker from getting it done is join spec, but not any technical difficulties, someone knowledgeable should come up with a more detail join spec. Mongoid does some denormalization internally I believe. |
issue #120
Hi, I've added support for mongoid, but without associations.
Here what I've done:
adapters/active_record
adapters/active_record/ransack
adapters/mongoid
Attribute
class for mongoid that imitatesArel::Attributes::Attribute
$ rake
runs active_record specs. default$ DB=mongodb rake
runs mongoid specs