Skip to content

Instantly share code, notes, and snippets.

@ruprict
Created November 19, 2010 16:37
Show Gist options
  • Save ruprict/706737 to your computer and use it in GitHub Desktop.
Save ruprict/706737 to your computer and use it in GitHub Desktop.
Can't seem to get Mongoid to update references_many associations
class Project
embeds_many :layers
embeds_many :maps
end
class Layer
referenced_in :layer_type, :inverse_of=>:layers
references_many :maps, :stored_as => :array, :inverse_of=>:layers
embedded_in :project, :inverse_of=>:layers
end
class Map
embedded_in :project
references_many :layers, :stored_as => :array, :inverse_of=>:maps
end
class LayerType
references_many :layers, :stored_as=>:array, :inverse_of=>:layer_type
end
class LayerController
def update
@project=Project.find(params[:project_id])
@layer = @project.layers.find(params[:id])
respond_to do |format|
if @layer.update_attributes(params[:layer]) #Does not fail, but associations not updated
...blah... #map_config_ids not set, layer_type_id not set
else
...blah...
end
end
end
end
# Parameters sent to update request
Processing by LayersController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"blah=", "layer"=>{"name"=>"Test Layer", "layer_type_id"=>"map-service", "min_zoom_level"=>"0", "max_zoom_level"=>"10", "map_ids"=>["", "test-map"]}, "commit"=>"Update Layer", "project_id"=>"test-project", "id"=>"test-layer"}
editor_development['users'].find({:_id=>BSON::ObjectId('4ce5d8982302c90539000002')}, {}).limit(-1)
editor_development['projects'].find({:_id=>"test-project"}, {}).limit(-1)
Redirected to http://localhost:3000/projects/test-project
Completed 302 Found in 3ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment