If I delete an object that has child objects, does rails automatically delete them as well or do I need to do it?
Say I have a model called Project and a model called Article. Project has_many articles and Article belongs_to a project. I can create a new article, but it only exists in the context of a project. Here is the destroy action from my ProjectController:
Should I add something in there that loops through all the child articles and deletes each one? If so, I'd guess that I would call a method in my model called something like kill_articles and pass it as an argument all the child articles. Any suggestions?Code:def destroy @project = Project.find(params[:id]) @project.destroy respond_to do |format| format.html { redirect_to project_url } format.xml { head :ok } end end





Bookmarks