Skip to content

Issue with parsing errors on associated models #110

@glappen

Description

@glappen

Hello,

I just encountered an issue where my API returns errors for an associated object. Let's say I have a User model, and a User has-many UserRoles. The errors json returned from my API looks like this:

{:errors=>
  {
    :email=>[
      {:error=>"blank"}
    ], 
    :"user_roles.years_of_experience"=>[{:error=>"blank"}]
  }
}

That is what I get when I call render json: { errors: @user.errors.details } in my API.

The error I get from Spyke is:

undefined method `user_roles.years_of_experience' for #<CoreClient::User:0x00007f1868008a70>
spyke (5.3.4) lib/spyke/attribute_assignment.rb:101:in `method_missing'
activemodel (5.2.2.1) lib/active_model/errors.rb:420:in `generate_message'
activemodel (5.2.2.1) lib/active_model/errors.rb:454:in `normalize_message'
activemodel (5.2.2.1) lib/active_model/errors.rb:298:in `add'
spyke (5.3.4) lib/spyke/http.rb:108:in `block (2 levels) in add_errors_to_model'

Is there any support for Spyke parsing errors for associated objects, or is it only working for attributes one level deep in the model being created? Maybe I'm not putting errors hash into the correct format.

Thanks!

Greg

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions