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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:02:31+00:00 2026-06-04T02:02:31+00:00

The joiner model is not being saved when I try this (assuming Account has_many

  • 0

The joiner model is not being saved when I try this (assumingAccount has_many :users, through: :roles and vice-versa):

def new
  @account = current_user.accounts.build
end
def create
  @account = current_user.accounts.build(params[:account])
  @account.save # does not save the joiner model
end

That should create @account, and a Role record where user_id=current_user.id and account_id: @account.id. Only @account gets saved. There are not records in the Role model. The results are consistent using console.

Replace current_user.accounts.build with current_user.accounts.create in the create action, the joiner (role record) model gets saved. For this reason I don’t think this is a validation issue. I’m using Rails 3.2.3.

Models:

class User < ActiveRecord::Base
  has_many :roles
  has_many :accounts, through: :roles
end
class Account < ActiveRecord::Base
  has_many :roles
  has_many :users, through: :roles
  accepts_nested_attributes_for :users
end
class Role < ActiveRecord::Base
  attr_accessible
  belongs_to :users
  belongs_to :accounts
end

View

<%= simple_form_for(@account) do |f| %>      
  <%= render 'account_fields', f: f %>
  <%= f.submit %>
<% end %>
  • 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-04T02:02:32+00:00Added an answer on June 4, 2026 at 2:02 am

    This is a bug: https://github.com/rails/rails/issues/6161#issuecomment-5631018

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

Sidebar

Related Questions

I have projects and users joined via has_many :through join model called ownerships. Each
I am creating a model for users and I want that property joined was
I've read many posts about this, the last being a statement saying the behaviour
Django auth User model has a date_joined DateTimeField . Could this be used to
I've been working on a project with a has_many :through relationship between a Story
My model looks like this: InsurancePolicy VehicleInsurancePolicy AbcInsurancePolicy DefInsurancePolicy HomeInsurancePolicy GhiInsurancePolicy PqrInsurancePolicy SomeOtherInsurancePolicy ...
I have joined models like this: // /foo/lib/model/doctrine/PurchasedItemTable.class.php public function retrievePurchased(Doctrine_Query $q) { $rootAlias
This 3 tables are just a part of my entire project (users,profile,login) Login.php (
in my users model, I have the following: @users = find(:all, :joins => :instance,
Hi i'm having a little trouble with a has_many through relationship for my app

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.