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

to_callback.rb calls mongoid pull with too many arguments #16

Closed
silasdavis opened this issue Jun 26, 2013 · 4 comments
Closed

to_callback.rb calls mongoid pull with too many arguments #16

silasdavis opened this issue Jun 26, 2013 · 4 comments

Comments

@silasdavis
Copy link

I am using mongoid and mongoid_alize from git and Rails 4.0.0

I have the relation

has_many :apks, :class_name => 'InjectedApk'
alize :apks

in a model called Distribution, and I am trying to add to the apks collection:

distribution.apks << injected_apk

However it throws a wrong number of arguments (2 for 1) argument error. It seems to be because in to_callable.rb the pull_from_inverse method calls pull from mongoid with too many arguments (from: https://github.com/dzello/mongoid_alize/blob/master/lib/mongoid/alize/to_callback.rb?source=c#L36):

relation.pull(prefixed_name, { "_id" => self.id })

Looks like pull may have changed/been refactored in recent mongoid verson: https://github.com/mongoid/mongoid/blob/master/lib/mongoid/persistable/pullable.rb

here is my stack trace starting from where it leaves my class:

/home/silas/.rvm/gems/ruby-2.0.0-p0@global/bundler/gems/mongoid-06b708d37cde/lib/mongoid/persistable/pullable.rb:23:in `pull'
/home/silas/.rvm/gems/ruby-2.0.0-p0@global/bundler/gems/mongoid-06b708d37cde/lib/mongoid/relations/proxy.rb:148:in `method_missing'
/home/silas/.rvm/gems/ruby-2.0.0-p0@global/bundler/gems/mongoid_alize-edb19b03b4d6/lib/mongoid/alize/to_callback.rb:44:in `block in _denormalize_to_distribution'
/home/silas/.rvm/gems/ruby-2.0.0-p0@global/bundler/gems/mongoid_alize-edb19b03b4d6/lib/mongoid/alize/to_callback.rb:22:in `each'
/home/silas/.rvm/gems/ruby-2.0.0-p0@global/bundler/gems/mongoid_alize-edb19b03b4d6/lib/mongoid/alize/to_callback.rb:22:in `_denormalize_to_distribution'
activesupport (4.0.0) lib/active_support/callbacks.rb:385:in `_run__1686143509039643885__save__callbacks'
activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks'
/home/silas/.rvm/gems/ruby-2.0.0-p0@global/bundler/gems/mongoid-06b708d37cde/lib/mongoid/interceptable.rb:132:in `run_callbacks'
/home/silas/.rvm/gems/ruby-2.0.0-p0@global/bundler/gems/mongoid-06b708d37cde/lib/mongoid/persistable/creatable.rb:116:in `prepare_insert'
/home/silas/.rvm/gems/ruby-2.0.0-p0@global/bundler/gems/mongoid-06b708d37cde/lib/mongoid/persistable/creatable.rb:23:in `insert'
/home/silas/.rvm/gems/ruby-2.0.0-p0@global/bundler/gems/mongoid-06b708d37cde/lib/mongoid/persistable/savable.rb:23:in `save'
/home/silas/.rvm/gems/ruby-2.0.0-p0@global/bundler/gems/mongoid-06b708d37cde/lib/mongoid/relations/referenced/many.rb:35:in `<<'
app/models/injected_apk.rb:27:in `from_original_and_distribution'
@joshed-io
Copy link
Owner

Agreed, it does look like it was changed in mongoid. I will try and get to this in the next week or so, but pull requests are welcome too!

@silasdavis
Copy link
Author

Might give that a go, but there is a bit of meta-foo to get my head around ;) Is there any reason why the class_eval is done using a string rather than a block in to_callback.rb? The latter is a bit nicer to work with, so I may refactor if there is no reason not to.

@joshed-io
Copy link
Owner

I imagine a block could be used, I think I went with the Strings because it looked more readable. Feel free to experiment, the test coverage is fairly extensive so we'll know if something breaks :)

@joshed-io
Copy link
Owner

Fixed.

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