Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Netflix/fast_jsonapi
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: eLocal/fast_jsonapi
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Checking mergeability… Don’t worry, you can still create the pull request.
  • 2 commits
  • 1 file changed
  • 2 contributors

Commits on Apr 13, 2018

  1. Spec to illustrate error thrown when including fast_jsonapi

    When trying to use the fast_jsonapi gem, we started getting an exception in unrelated `ActiveRecord` code like:
    
    ```
     Failure/Error:
       def #{name}_id
         association(:#{name}).reader.try(:id)
    
     NoMethodError:
       undefined method `has_scope?' for nil:NilClass
     # ./vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.6/lib/active_record/reflection.rb:872:in `has_scope?'
     # ./vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.6/lib/active_record/reflection.rb:873:in `has_scope?'
     # ./vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.6/lib/active_record/associations/association.rb:288:in `skip_statement_cache?'
     # ./vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.6/lib/active_record/associations/singular_association.rb:39:in `find_target'
     # ./vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.6/lib/active_record/associations/association.rb:157:in `load_target'
     # ./vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.6/lib/active_record/associations/association.rb:53:in `reload'
     # ./vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.6/lib/active_record/associations/singular_association.rb:7:in `reader'
     # ./lib/extensions/has_one.rb:15:in `city_id'
    
    ```
    
    This error was only showing when we had required in the `fast_jsonapi` and was happening in code that was not doing JSON serialization.
    
    The reason for the error was that we were making a call to an `ActiveRecord` `select` where we were explicitly selecting the ID value for a `has_one` that was coming through another relation.
    
    The `HasOne` monkey patch in `lib/extensions/has_one.rb` is the cause of this error.
    
    The spec above illustrates the problem. If you run it, you will see the above exception. If you comment out the code in `lib/extensions/has_one.rb`, you will see the new spec passes.
    Rob Di Marco committed Apr 13, 2018
    Configuration menu
    Copy the full SHA
    323ef31 View commit details
    Browse the repository at this point in the history

Commits on Apr 21, 2018

  1. Configuration menu
    Copy the full SHA
    5b18a43 View commit details
    Browse the repository at this point in the history
Loading