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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:43:01+00:00 2026-06-13T11:43:01+00:00

Given the relationship expressed below: class Parent < ActiveRecord::Base has_many :children, :dependent => :destroy

  • 0

Given the relationship expressed below:

class Parent < ActiveRecord::Base
  has_many :children, :dependent => :destroy

  accepts_nested_attributes_for :child
end

class Child < ActiveRecord::Base
  belongs_to :parent

  validates :name, :presence => true
end

Let’s assume we have a parent object with multiple children, one or more of which have errors that cause parent.valid? to return false.

parent = Parent.new
parent.build_child(:name => "steve")
parent.build_child()
parent.valid?

Is there a way to access the child element that caused the errors when looking at the parent.errors object?

  • 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-13T11:43:02+00:00Added an answer on June 13, 2026 at 11:43 am

    As John suggested in the comments, I ended up ignoring the errors added to the parent for the children and traversing the children and adding their errors manually. The issue was complicated by having a couple has_many :through relationships, but John’s suggestion was the essence of what I ended up using.

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

Sidebar

Related Questions

Rails 3.0.4 Given the following relationship class Child < ActiveRecord::Base belongs_to :parent end class
Given User: class User < ActiveRecord::Base has_many :discussions has_many :posts end Discussions: class Discussion
Given you have a domain model with a simple parent / child relationship, and
Given a parent child relationship between User and FailedLogin where a user has many
I've been given a SQL table that has a parent-child relationship that I'd like
given a Python class hierarchy, say class Base: def method1 def method2 def method3
Given a simple entity relationship: @Entity public class Single { @OneToMany public Set<Multiple> multiples;
Given a simple relationship where Person has_many Telephones. And a telephone only contains a
i need such a query where child and parent field are given with a
Given the jQuery dropdown plugin below. Is there a way to add a method

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.