-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
When I create these models:
class Jar include Mongoid::Document identity type: Integer has_many :cookies end
class Cookie include Mongoid::Document belongs_to :jar end
and I then try to create a Jar with a specific id like this:
Jar.create(:id => 1)
I get this error:
TypeError: can't convert Fixnum into String from /Users/keeker1/.rvm/gems/ruby-1.9.2-p290@geoverse/gems/mongoid-2.2.0/lib/mongoid/criterion/unconvertable.rb:17:in `initialize' from /Users/keeker1/.rvm/gems/ruby-1.9.2-p290@geoverse/gems/mongoid-2.2.0/lib/mongoid/criterion/unconvertable.rb:17:in `initialize' from /Users/keeker1/.rvm/gems/ruby-1.9.2-p290@geoverse/gems/mongoid-2.2.0/lib/mongoid/relations/builders/referenced/many.rb:40:in `new' from /Users/keeker1/.rvm/gems/ruby-1.9.2-p290@geoverse/gems/mongoid-2.2.0/lib/mongoid/relations/builders/referenced/many.rb:40:in `convertable' from /Users/keeker1/.rvm/gems/ruby-1.9.2-p290@geoverse/gems/mongoid-2.2.0/lib/mongoid/relations/builders/referenced/many.rb:20:in `build' from /Users/keeker1/.rvm/gems/ruby-1.9.2-p290@geoverse/gems/mongoid-2.2.0/lib/mongoid/relations/accessors.rb:43:in `create_relation' from /Users/keeker1/.rvm/gems/ruby-1.9.2-p290@geoverse/gems/mongoid-2.2.0/lib/mongoid/relations/accessors.rb:26:in `build' from /Users/keeker1/.rvm/gems/ruby-1.9.2-p290@geoverse/gems/mongoid-2.2.0/lib/mongoid/relations/accessors.rb:100:in `block (3 levels) in getter' from /Users/keeker1/.rvm/gems/ruby-1.9.2-p290@geoverse/gems/mongoid-2.2.0/lib/mongoid/relations/builders.rb:47:in `building' from /Users/keeker1/.rvm/gems/ruby-1.9.2-p290@geoverse/gems/mongoid-2.2.0/lib/mongoid/relations/accessors.rb:99:in `block (2 levels) in getter' from /Users/keeker1/.rvm/gems/ruby-1.9.2-p290@geoverse/gems/mongoid-2.2.0/lib/mongoid/validations.rb:47:in `read_attribute_for_validation' from /Users/keeker1/.rvm/gems/ruby-1.9.2-p290@geoverse/gems/activemodel-3.1.0.rc6/lib/active_model/validator.rb:151:in `block in validate' from /Users/keeker1/.rvm/gems/ruby-1.9.2-p290@geoverse/gems/activemodel-3.1.0.rc6/lib/active_model/validator.rb:150:in `each' from /Users/keeker1/.rvm/gems/ruby-1.9.2-p290@geoverse/gems/activemodel-3.1.0.rc6/lib/active_model/validator.rb:150:in `validate' from /Users/keeker1/.rvm/gems/ruby-1.9.2-p290@geoverse/gems/activesupport-3.1.0.rc6/lib/active_support/callbacks.rb:302:in `_callback_before_11' from /Users/keeker1/.rvm/gems/ruby-1.9.2-p290@geoverse/gems/activesupport-3.1.0.rc6/lib/active_support/callbacks.rb:395:in `_run_validate_callbacks' ... 10 levels... from /Users/keeker1/.rvm/gems/ruby-1.9.2-p290@geoverse/gems/mongoid-2.2.0/lib/mongoid/persistence/insertion.rb:22:in `tap' from /Users/keeker1/.rvm/gems/ruby-1.9.2-p290@geoverse/gems/mongoid-2.2.0/lib/mongoid/persistence/insertion.rb:22:in `prepare' from /Users/keeker1/.rvm/gems/ruby-1.9.2-p290@geoverse/gems/mongoid-2.2.0/lib/mongoid/persistence/operations/insert.rb:26:in `persist' from /Users/keeker1/.rvm/gems/ruby-1.9.2-p290@geoverse/gems/mongoid-2.2.0/lib/mongoid/persistence.rb:44:in `insert' from /Users/keeker1/.rvm/gems/ruby-1.9.2-p290@geoverse/gems/mongoid-2.2.0/lib/mongoid/persistence.rb:149:in `upsert' from /Users/keeker1/.rvm/gems/ruby-1.9.2-p290@geoverse/gems/mongoid-2.2.0/lib/mongoid/persistence.rb:170:in `block (2 levels) in create' from /Users/keeker1/.rvm/gems/ruby-1.9.2-p290@geoverse/gems/mongoid-2.2.0/lib/mongoid/persistence.rb:170:in `tap' from /Users/keeker1/.rvm/gems/ruby-1.9.2-p290@geoverse/gems/mongoid-2.2.0/lib/mongoid/persistence.rb:170:in `block in create' from /Users/keeker1/.rvm/gems/ruby-1.9.2-p290@geoverse/gems/mongoid-2.2.0/lib/mongoid/persistence.rb:273:in `creating' from /Users/keeker1/.rvm/gems/ruby-1.9.2-p290@geoverse/gems/mongoid-2.2.0/lib/mongoid/persistence.rb:169:in `create' from (irb):15 from /Users/keeker1/.rvm/gems/ruby-1.9.2-p290@geoverse/gems/railties-3.1.0.rc6/lib/rails/commands/console.rb:45:in `start' from /Users/keeker1/.rvm/gems/ruby-1.9.2-p290@geoverse/gems/railties-3.1.0.rc6/lib/rails/commands/console.rb:8:in `start' from /Users/keeker1/.rvm/gems/ruby-1.9.2-p290@geoverse/gems/railties-3.1.0.rc6/lib/rails/commands.rb:40:in `<top (required)>' from script/rails:6:in `require' from script/rails:6:in `<main>'
It seems like when a collection has an identity of type Integer and it's being referenced by another collection it throws this error. If you remove the association to cookies everything is fine.
Thanks