Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3337368
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:14:41+00:00 2026-05-18T00:14:41+00:00

Okay, so here’s an example scenario. There is a student resource resources :students ,

  • 0

Okay, so here’s an example scenario. There is a student resource resources :students, and students has and belongs to many collections: resources :clubs, resources :majors, etc.

So we can set up our routes easily enough…

resources :clubs do
  resources :students
end
resources :majors do
  resources :students
end
resources :students do
  resources :clubs
  resources :majors
end

which generates us a bunch of standard RESTful routes

  • /clubs
  • /clubs/:id
  • /clubs/:club_id/students
  • /clubs/:club_id/students/:id
  • /majors
  • /majors/:id
  • /majors/:major_id/students
  • /majors/:major_id/students/:id
  • /students
  • /students/:id
  • /students/:student_id/clubs
  • /students/:student_id/clubs/:id
  • /students/:student_id/majors
  • /students/:student_id/majors/:id

So here’s my question. With REST semantics, how would one delete a major for a student?
Browsing students under a major /majors/:major_id/students/:id would show that student in the specific major’s ‘collection’. But the route for deleting an :id, points to StudentsController#destroy, which would delete the student completely. Whoops! So maybe we go the other way, and perform DELETE on the resource at /students/:student_id/majors/:id and well now UnderwaterBasketweaving is now no longer offered at this school…Whoops!

Now granted, we could set the destroy method of ClubsController, MajorsController, or StudentsController to look for club_id, or major_id, or student_id, but lets say we also down the road want to add Fraternities and GraduatingClasses, etc. Each class would start to be comprised of huge switch conditionals looking to see what param was present… and then find the collection of either the top resource and remove the bottom resource, or vise versa. The Models themselves should decide whether they delete themselves if they have no more association records… ‘Destroy’ on that resource has become really a misnomer…

Is there an easier way to do this? Even popular restful rails plugins like make_resourceful or resource_controller would blow away UnderwaterBasketweaving when removing it from Joe’s Majors or completely delete JohnDoe when removing him from the major UnderwaterBasketweaving. It would seem there’s a potential for looking at the association to understand the desired effects of the semantics and what ‘destroy’ should do.

Then again, am I looking at this all wrong? Is it not UnderwaterBasketweaving -> Joe but UnderwaterBasketweaving+Joe as a single resource and what we’re deleting is truly not Joe, nor UnderwaterBasketweaving, but the resource representing the combination? However, that’s not easy when the controllers are Students and Majors, that in effect represent resources of the same name (MVC has really become RV…in the ‘convention’ approach and not developing Controllers that may have no bearing on a Model name, or the path to reach it) So you’d be deleting a Major or a Student; pick your poison…

How can I avoid managing conditionals across an infinite graph of associated resources where delete really isn’t the intent when the delete is desired to be in context of a collection and not pertaining to its singularity…?

…major.student.delete… Is there a way for ‘student’ ActiveRecord object to know it was sent a ‘delete’ message in a method chain beginning with the ‘major’ AR object ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T00:14:42+00:00Added an answer on May 18, 2026 at 12:14 am

    Well the standard RESTful aproach is to use has_many :through and generate a cotroller for the association resource. Naming association resources is always difficult, but I’ll attempt for this example.

    resources :majors do
      resources :studies
      resources :students
    end
    resources :students do
      resources :studies
      resources :majors
    end
    

    The models would be of course:

    class Major < ActiverRecord::Base
      has_many :studies
      has_many :students, :through => :studies
    end
    

    etc. (comment if you want me to elaborate)

    Then for a student you wouldn’t DELETE it’s associated @student.major but his @student.studies.where :major => @major.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay here is the scenario! I have a Person object which has an Address
Okay, here's the scenario. I have a utility that processes tons of records, and
Okay here's the program I have typed up(stdio.h is included also): /* function main
Okay here is what I'm, trying to do I want to escape the period
Okay here is a softball beginner WPF question. By default the background of the
Okay here's the damned thing: - (void)setMinimumNumberOfSides:(NSNumber *)newMinimumNumberOfSides { if (newMinimumNumberOfSides != minimumNumberOfSides) {
Okay here is a puzzle I come across a lot of times- Given a
Hey all. Okay here is the situation. I would like to be able to
Okay so I have a scenario similar to the below code, I have a
Okay, I've looked all over the internet for a good solution to get PHP

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.