Skip to content

Desired behaviour when model is not found #321

@ramontayag

Description

@ramontayag

I created a resource (let's say ArticleResource) and the model is called Page. You can fix this by setting the model name on the resource, but if you forget to do that you get a cryptic error undefined methodorder' for nil`. See the top part of the error here:

Internal Server Error: undefined method `order' for nil:NilClass /home/vagrant/.rvm/gems/ruby-2.1.5/gems/jsonapi-resources-0.5.0/lib/jsonapi/resource.rb:439:in `apply_sort'
/home/vagrant/.rvm/gems/ruby-2.1.5/gems/jsonapi-resources-0.5.0/lib/jsonapi/resource.rb:481:in `sort_records'
/home/vagrant/.rvm/gems/ruby-2.1.5/gems/jsonapi-resources-0.5.0/lib/jsonapi/resource.rb:496:in `find'
/home/vagrant/.rvm/gems/ruby-2.1.5/gems/jsonapi-resources-0.5.0/lib/jsonapi/operation.rb:45:in `apply'
/home/vagrant/.rvm/gems/ruby-2.1.5/gems/jsonapi-resources-0.5.0/lib/jsonapi/active_record_operations_processor.rb:19:in `process_operation'
/home/vagrant/.rvm/gems/ruby-2.1.5/gems/jsonapi-resources-0.5.0/lib/jsonapi/operations_processor.rb:55:in `block (5 levels) in process'
/home/vagrant/.rvm/gems/ruby-2.1.5/gems/activesupport-4.1.12/lib/active_support/callbacks.rb:82:in `run_callbacks'

What would the desired behaviour be? Perhaps raise an exception model Article could not be found for ArticleResource? I do not mind making this change.

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