Topic: Deleting child object with Edge Rest interface...
I was just minding my own business, playing with Edge and the Restful interface it had, when mysql started giving me errors. I'm just playing around, but I'd like to know if I've hit a bug, incomplete feature, or if I misunderstood what I was supposed to write in.
In general, a world has many story_arcs, and a story_arc belongs to a world. Worlds are CRUDy and the Story Arcs have the CRU, but the D causes the following error:
Mysql::Error: Cannot add or update a child row: a foreign key constraint fails: UPDATE story_arcs SET world_id = NULL WHERE (world_id = 1 AND id IN (1))
Here's some of the relevant code.
routes.rb
...
map.resources :worlds do |world|
world.resources :story_arcs
end
story_arc_controller.rb
def destroy
story_arc = @world.story_arcs.find(params[:id].to_i)
@world.story_arcs.delete(story_arc)respond_to do |format|
format.html { redirect_to story_arcs_path }
format.xml { head :ok }
end
end
_story_arc.rhtml
<%= link_to 'Destroy', story_arc_path(:id => story_arc,
:world_id => story_arc.world), :confirm => 'Are you sure?', :method => :delete %></td>
I'm all about messing with fire: I just want to know if I'm burning myself or if the stove is faulty.
Any help would be appreciative
Last edited by LifeIsGood (2006-11-11 15:26:40)