Skip to content

Using with accepts_nested_attributes_for does not show error message for child object #69

Description

@andreaflether

Hello,

I started using the gem considering the Rails problem with uniqueness and accepts_nested_attributes_for, but I'm having a problem that I'm not sure it's a gem limitation or a implementation error of mine.

I have these relationships/models:

class Team < ApplicationRecord
   has_many :requested_units, index_errors: true
   accepts_nested_attributes_for :requested_units
end
class RequestedUnit < ApplicationRecord
   belongs_to :team
   validates_db_uniqueness_of :code, index_name: 'IX_REQ_UNIT_CODE', scope: %i[team_id], rescue: :always
end

I think the uniqueness itself works well since the log shows an rollback (ROLLBACK TO SAVEPOINT active_record_1), but when doing @team.errors, there is no errors to be displayed, and the object is stated as valid.

3.2.2 :020 > team = Team.new(requested_units_attributes: [{ code: 111 }, { code: 111 }])
=> #<Team:0x00007f7c5c1bf500 id: nil, name: "Test">

3.2.2 :021 > team.valid?
=> false

3.2.2 :022 > team.errors                                                                                                                                                                       
=> #<ActiveModel::Errors []>

Rails version: 7.0.7
Ruby version: 3.2.2

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions