Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatible with ActiveModel 6.1 #75

Open
rewritten opened this issue Sep 20, 2021 · 0 comments
Open

Incompatible with ActiveModel 6.1 #75

rewritten opened this issue Sep 20, 2021 · 0 comments

Comments

@rewritten
Copy link
Contributor

rewritten commented Sep 20, 2021

The ActiveModel::Errors class has changed, keeping most of the high level API compatible, but some of the underlying implementation are not working anymore.

The class ActiveData::Model::Validations::NestedValidator is not compatible with the new implementation, it should be something on the lines of:

def self.validate_nested(record, name, value)
  if value.is_a?(Enumerable)
    value.each.with_index do |object, i|
      if yield(object)
        object.errors.each do |error|
          record.errors.import(error, attribute: "#{name}.#{i}.#{error.attribute}")
        end
      end
    end
  elsif value && yield(value)
    value.errors.each do |error|
      record.errors.import(error, attribute: "#{name}.#{error.attribute}")
    end
  end
end

but of course this only works with the new errors interface… so maybe a version check? I haven't been able to find a version-independent way to achieve it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant