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

  • Home
  • SEARCH
  • 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 8150123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:59:19+00:00 2026-06-06T14:59:19+00:00

Ok, so I have 2 models with a has_many :through relationship: class Server <

  • 0

Ok, so I have 2 models with a has_many :through relationship:

class Server < ActiveRecord::Base
  has_many :services, :through :servers_services, :dependent => :destroy
  has_many :servers_services, :dependent => :destroy

  def destroy!
    options = {:name => self.name, :services => self.services.map { |s| s.attributes }}
    Resque.enqueue(Cluster::DestroyServer, options)
    self.destroy 
  end
end

and

class Service
  has_many :servers, :through => :servers_services
  has_many :servers_services
end

These are connected through:

class ServersService < ActiveRecord::Base
  belongs_to :server
  belongs_to :service
end

The destroy! method in the Server model previously worked, but now doesn’t do what it should. It should find all Services associated with the Server, trigger the Resque task (which works) and then destroy the Server and its associated Services.

What is happening however, is that it is destroy ALL ServerServices (literally the whole table), not just the ones associated with the Server object, which breaks all of the associations. Is there something obvious I’m missing here?

  • 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-06-06T14:59:21+00:00Added an answer on June 6, 2026 at 2:59 pm

    This was being caused by a broken postgresql sequence on the ID column on the servers_services table. Fixed the sequence so that there is a valid primary key and everything works as expected again.

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

Sidebar

Related Questions

I have three models: class Book < ActiveRecord::Base has_many :collections has_many :users, :through =>
I have the following models: class Person < ActiveRecord::Base has_many :accounts, :through => :account_holders
I have the following models class Project < ActiveRecord::Base has_many :project_members has_many :members, :through
I have 2 models: Video: class Video < ActiveRecord::Base belongs_to :user has_many :thumbnails attr_accessor
I have three models: class Address < ActiveRecord::Base has_many :jobs end class Category <
I've got my models setup for a many-to-many relationship: class Workshop < ActiveRecord::Base has_many
I have the following models: require 'books_projects.rb' class Project < ActiveRecord::Base has_many :book_to_projects has_many
I have the following models: school.rb class School < ActiveRecord::Base has_many :offers has_many :players,
i have three models, all for a has_many :through relationship. They look like this:
I made a relationship with the three models using has_many :through : class Curriculum

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.