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 8349741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:06:04+00:00 2026-06-09T08:06:04+00:00

I am having difficulty with my associations and have been digging around trying to

  • 0

I am having difficulty with my associations and have been digging around trying to find an answer relevant to my problem. I have a selection box in my form that adds users to a study when it is created. The problem is that if I edit the list and remove a user from a study and then add them back it deletes their answers. I am still learning RoR and have been given the task of getting some existing code to function this way. The study model has many users through answers, so how do I edit the study users without deleting the answers? my form:

= select_tag("users[]", options_for_select(@users.collect { |ff| [ff.full_name, ff.id] }, @study.users.collect { |fs| fs.id }), | {:multiple=>true, :id => "users"})                                                                                      |

my study.rb:

has_many :users, :through => :answers
has_many :answers, :group => :grouping_number
accepts_nested_attributes_for :answers 

my user.rb

has_many :answers
has_many :studies, :through => :answers

my answer.rb

belongs_to :user
belongs_to :study
belongs_to :question

I realize that this may be something simple that I have overlooked, which is often the case when spending too long looking at something, but any point in the right direction would be much appreciated.

  • 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-09T08:06:06+00:00Added an answer on June 9, 2026 at 8:06 am

    You might benefit from using a Soft Delete gem like acts_as_paranoid.

    This way the associations will remain intact but be flagged as deleted instead of actually being removed from the database. The benefit of this is you can still query active record for user’s answers even after their study association is ‘deleted’, while the behavior of the association actually having been deleted from the application will remain the same.

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

Sidebar

Related Questions

I'm having difficulty with this problem. I have a table with this structure: OrderID
Im having difficulty trying to design a database structure for the following scenario: My
I'm essentially having difficulty pass dynamic variables to a view. I have php functions
I am having difficulty using JQuery UI Modal Dialog when submitting a form. The
I've been having difficulty getting anything more than a simple index / to return
Having difficulty making my javascript act the way I want. I have a button,
Having difficulty finding relevant search results... Given this model: public abstract class A {
I'm having difficulty getting my textarea to expand vertically automatically. I have some code
I'm having difficulty scanning for the special character [. After looking around, I've tried:
Having difficulty articulating this correlated subquery. I have two tables fictitious tables, foo and

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.