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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T15:23:02+00:00 2026-05-21T15:23:02+00:00

Hm, First time i see this when i want to delete row: ( I

  • 0

Hm, First time i see this when i want to delete row: ( I want to delete respondent.email) i got his:

Mysql::Error: Cannot delete or update a parent row: a foreign key constraint fails (`survey_development`.`inquiries`, CONSTRAINT `inquiries_ibfk_2` FOREIGN KEY (`respondent_id`) REFERENCES `respondents` (`id`)): DELETE FROM `respondents` WHERE `id` = 4

p.s

users (table): id, email 
questions (table): id, text 
inquiries: question_id, user_id 
answers: inquiry_id, text

Model of users:

has_many :inquiries 
has_many :questions, :through => :inquiries 
has_many :answers, :through => :inquiries

question model:

has_many :inquiries, :dependent => :destroy 
has_many :answers, :through => :inquiries, :dependent => :destroy 

answer model

  belongs_to :inquiry
  belongs_to :question

inquiry model

  belongs_to  :question
  belongs_to  :users
  has_one    :answer, :dependent => :destroy

respondents_controller

  # DELETE /respondents/1
  def destroy
    @respondent.destroy
    head :ok
  end

respondent_model

class Respondent < ActiveRecord::Base
  has_many :inquiries
  has_many :questions, :through => :inquiries
  has_one :answer,   :through => :inquiry
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-05-21T15:23:03+00:00Added an answer on May 21, 2026 at 3:23 pm

    Let’s start.

    First – it is wrong code:

    class Respondent < ActiveRecord::Base
      has_many :inquiries
      has_many :questions, :through => :inquiries
      has_one :answer,   :through => :inquiry
    end
    

    Second, you havent got respondent_id in your inquiries table and you should define

    has_many :respondents
    

    in your Inquiry model.

    Third you can’t use this

    has_one :answer,   :through => :inquiry
    

    as far as association inquiry is not defined.

    So you should

    • add respondent_id to your inquiries table
    • add belongs_to :respondent association to your Inquiry model
    • delete has_one :answer, :through => :inquiry association from Respondent model. Or figure out what is it and add some new association to fix it.

    And read some articles about Rails associations.

    Your problem is not a bad code. Your problem is that you don’t understand what you are doing. You should feel Rails and you should love Rails. God bless you

    Also you haven’t got question_id in your answers table.

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

Sidebar

Related Questions

Well, I'm sure this is not the first time to see this question. and
I see time.clock() on Windows 'starts' a timer when called for the first time,
It is not the first time i see it Ive seen in Facebook source
I'm familiarizing myself with Ruby and it's the first time I see synonyms for
first time poster, long time reader so be gentle with me :) See the
I'm a long running fan of stackoverflow, first time poster. I'd love to see
first time poster. Please be gentle. This topic may be similar to several other
I downloaded QTP version 11 for the first time to see what is QTP
First time I post a question, so here it goes. I want to push
I see this time and time again. The UAT test manager wants the new

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.