{"issue":{"state":"open","created_at":"2011-12-08T14:33:15Z","updated_at":"2011-12-08T14:33:15Z","comments":0,"user":{"gravatar_id":"2a166cd57b95c3c74b12b4a32b356059","id":858379,"url":"https://api.github.com/users/jjoe64","avatar_url":"https://secure.gravatar.com/avatar/2a166cd57b95c3c74b12b4a32b356059?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","login":"jjoe64"},"body":"if have a one-to-many relation in my model:\r\n\r\n```\r\nclass Office\r\n  include MongoMapper::Document\r\n  many :journey_descriptions\r\n  accepts_nested_attributes_for :journey_descriptions\r\nend\r\n\r\nclass JourneyDescription\r\n  include MongoMapper::EmbeddedDocument\r\nend\r\n```\r\n\r\nIn the view I generate a nested form (using formtastic):\r\n```\r\n  = form.inputs :name => t(\"offices.journey_description\")+\" %i\", :for => :journey_descriptions do |jd_form|\r\n    = jd_form.input :title\r\n```\r\n\r\nThe form looks good, but when I want to save, this error comes up:\r\n\r\ncan't convert String into Integer\r\n\r\n### Stacktrace:\r\n> mongo_mapper (0.9.2) lib/mongo_mapper/plugins/keys.rb:69:in `[]'\r\n> mongo_mapper (0.9.2) lib/mongo_mapper/plugins/keys.rb:69:in `load'\r\n> mongo_mapper (0.9.2) lib/mongo_mapper/plugins/associations/many_embedded_proxy.rb:16:in `block in find_target'\r\n> mongo_mapper (0.9.2) lib/mongo_mapper/plugins/associations/many_embedded_proxy.rb:15:in `map'\r\n> mongo_mapper (0.9.2) lib/mongo_mapper/plugins/associations/many_embedded_proxy.rb:15:in `find_target'\r\n> mongo_mapper (0.9.2) lib/mongo_mapper/plugins/associations/proxy.rb:113:in `load_target'\r\n> mongo_mapper (0.9.2) lib/mongo_mapper/plugins/associations/proxy.rb:94:in `send'\r\n> mongo_mapper (0.9.2) lib/mongo_mapper/plugins/embedded_callbacks.rb:18:in `block in run_callbacks'\r\n> mongo_mapper (0.9.2) lib/mongo_mapper/plugins/embedded_callbacks.rb:17:in `each'\r\n> mongo_mapper (0.9.2) lib/mongo_mapper/plugins/embedded_callbacks.rb:17:in `run_callbacks'\r\n> mongo_mapper (0.9.2) lib/mongo_mapper/plugins/validations.rb:86:in `run_validations!'\r\n> activemodel (3.1.1.rc1) lib/active_model/validations.rb:179:in `valid?'\r\n> mongo_mapper (0.9.2) lib/mongo_mapper/plugins/validations.rb:28:in `valid?'\r\n> mongo_mapper (0.9.2) lib/mongo_mapper/plugins/validations.rb:23:in `save'\r\n> mongo_mapper (0.9.2) lib/mongo_mapper/plugins/keys.rb:220:in `update_attributes'\r\n> mongo_mapper (0.9.2) lib/mongo_mapper/plugins/accessible.rb:23:in `update_attributes'\r\n> mongo_mapper (0.9.2) lib/mongo_mapper/plugins/protected.rb:32:in `update_attributes'\r\n> app/controllers/offices_controller.rb:72:in `block in update'\r\n> actionpack (3.1.1.rc1) lib/action_controller/metal/mime_responds.rb:269:in `call'\r\n> actionpack (3.1.1.rc1) lib/action_controller/metal/mime_responds.rb:269:in `retrieve_response_from_mimes'\r\n> actionpack (3.1.1.rc1) lib/action_controller/metal/mime_responds.rb:194:in `respond_to'\r\n> app/controllers/offices_controller.rb:71:in `update'\r\n\r\n\r\n## Workaround\r\nI found out a workaround for this issue: You have to convert the journey_descriptions_attributes Hash to a Array.\r\n`params[:office][:journey_descriptions_attributes] = params[:office][:journey_descriptions_attributes].values`\r\n","assignee":null,"id":2488178,"labels":[],"number":358,"pull_request":{"patch_url":null,"html_url":null,"diff_url":null},"title":"nested forms not compatible with mongo_mapper","html_url":"https://github.com/jnunemaker/mongomapper/issues/358","closed_at":null,"url":"https://api.github.com/repos/jnunemaker/mongomapper/issues/358","milestone":null},"action":"opened"}