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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:38:42+00:00 2026-05-11T08:38:42+00:00

My question involves a few different active records class Respondent < ActiveRecord::Base has_many :phone_numbers,

  • 0

My question involves a few different active records

class Respondent < ActiveRecord::Base has_many :phone_numbers, :dependent => :destroy has_many :email_addresses, :dependent => :destroy belongs_to :phone_number, :foreign_key=> 'primary_phone_id' belongs_to :email_address, :foreign_key=> 'primary_email_id' end  class User < Respondent end  class EmailAddress < ActiveRecord::Base belongs_to :respondent has_one :respondent end 

The schema for these tables are

create_table 'email_addresses', :force => true do |t|   t.string   'email'   t.integer  'respondent_id' end  create_table 'respondents', :force => true do |t|   t.string   'first_name'   t.string   'last_name'   t.integer  'primary_email_id'   t.integer  'primary_phone_id'   t.string   'type' end 

What I am trying to accomplish is to have the respondents, and therefore users, capable of having multiple email address but only one primary. For this reason the email record and respondents record link to one another. All of the email address are stored in the email_address record and reference the respondent, and the respondent record has an id to only one email.

In the UserController the following code fails

def create     @user = User.new(params[:user])     @primary_email = EmailAddress.new(params[:primary_email])     User.transaction do       @user.primary_email = @primary_email  <=Undefined Method primary_email=       @user.save!       @primary_email.save!       redirect_to :action => :show, :id => @user     end end 

First, is this even possible what I am doing? How can I modify the code to make this controller code work?

  • 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. 2026-05-11T08:38:43+00:00Added an answer on May 11, 2026 at 8:38 am

    Yes, you just need Respondent to have as associated primary email:

    has_one :primary_email, :class_name => 'EmailAddress' 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 121k
  • Answers 121k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer i found in this link : http://phplens.com/lens/php-book/optimizing-debugging-php.php A function call… May 12, 2026 at 12:32 am
  • Editorial Team
    Editorial Team added an answer You might want to check out classkit May 12, 2026 at 12:31 am
  • Editorial Team
    Editorial Team added an answer <%= controller_name %> <%= action_name %> May 12, 2026 at 12:31 am

Related Questions

I've only dealt with one-to-one relationships in php so far, but I'm stuck on
I'm the sole developer for an academic consortium headquartered at a university in the
Consider the following setup: A windows PC with a LAN interface and a WiFi
I'm fond of using UML diagrams to describe my software. In the majority of

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.