kaminari-mongoid icon indicating copy to clipboard operation
kaminari-mongoid copied to clipboard

scope override errore when used with sublcasses

Open saten opened this issue 6 years ago • 6 comments

Hello,

our app has a class which includes Mongoid::Document and many subclasses. the following exception is thrown Mongoid::Errors::ScopeOverwrite when kaminari-mongoid attempts to add page scope to each of the subclasses (file mongoid_extensions:12)

mongoid 4.0.2 kaminari master kaminari-mongoid master

saten avatar Oct 18 '18 14:10 saten

Could you provide an example app or a test case that replicates your issue?

yuki24 avatar Oct 18 '18 14:10 yuki24

in theory you could replicate it easily doing the following

class Parent include Mongoid::Document end

class Child < Parent end

class OtherChild < Parent end

it should throw the exception when loading the file of the child class

saten avatar Oct 18 '18 15:10 saten

We have the exact same setup in the test and the build for Mongod 4.0 is green (I just re-ran just in case.) This is why we almost always ask for a test case or an example app that's actually runnable instead of a code snippet that doesn't necessarily replicates the issue.

Also, please use markdown to make your comments more readable. Plain text is very hard to read.

yuki24 avatar Oct 18 '18 15:10 yuki24

i'll try to reproduce it in a separate app. sorry for plain text, i'm replying by mail :(

saten avatar Oct 18 '18 15:10 saten

Hi, could not reproduce the exact behaviour, which I believe is tied to mongoid version.

The following repo is a brand new rails 4.1.x app with mongoid 4.0.2 and kaminari-mongoid

Try creating a Person::Individual record

https://github.com/dSmart-srl/sample_k

saten avatar Oct 18 '18 19:10 saten

Your example app seems to be working fine after applying the following diff:

diff --git a/Gemfile b/Gemfile
index fa3d1c3..3da07a2 100644
--- a/Gemfile
+++ b/Gemfile
@@ -1,12 +1,17 @@
 source 'https://rubygems.org'

+# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
+gem 'rails', '4.1.14'

 gem 'mongoid', '~> 4.0.x'
-gem 'kaminari'
+
+git 'https://github.com/kaminari/kaminari' do
+  gem 'kaminari-core'
+end
+
 gem 'kaminari-mongoid'

-# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
-gem 'rails', '4.1.14'
 # Use sqlite3 as the database for Active Record
 gem 'sqlite3'
 # Use SCSS for stylesheets
Parent::Individual.page(1)
# => #<Mongoid::Criteria
#   selector: {}
#   options:  {:limit=>25, :skip=>0}
#   class:    Parent::Individual
#   embedded: false>

yuki24 avatar Oct 18 '18 22:10 yuki24