From 1ad637eb12935b26bbb3ff79388389324e26bc51 Mon Sep 17 00:00:00 2001 From: Larry Gebhardt Date: Mon, 6 Apr 2015 11:39:53 -0400 Subject: [PATCH 1/3] Remove legacy code for mapping names to resources. --- lib/jsonapi/resource.rb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib/jsonapi/resource.rb b/lib/jsonapi/resource.rb index 7a9a1026d..035ce34b6 100644 --- a/lib/jsonapi/resource.rb +++ b/lib/jsonapi/resource.rb @@ -203,11 +203,6 @@ def inherited(base) base.attribute :id, format: :id check_reserved_resource_name(base._type, base.name) - - # If eager loading is on this is how all the resource types are setup - # If eager loading is off some resource types will be initialized in - # _resource_name_from_type - @@resource_types[base._type] ||= base.name.demodulize end def resource_for(type) From 900d23b5066dc856766190a62957bd9145bfb1d8 Mon Sep 17 00:00:00 2001 From: Larry Gebhardt Date: Mon, 6 Apr 2015 11:40:44 -0400 Subject: [PATCH 2/3] Remove eager_load setting. --- test/test_helper.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index b2ca32e53..c30f454b8 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -27,7 +27,6 @@ puts "Testing With RAILS VERSION #{Rails.version}" class TestApp < Rails::Application - config.eager_load = false config.root = File.dirname(__FILE__) config.session_store :cookie_store, key: 'session' config.secret_key_base = 'secret' From 875a81b8f8f04885b2c786186d748ec591a07b5b Mon Sep 17 00:00:00 2001 From: Larry Gebhardt Date: Mon, 6 Apr 2015 14:59:55 -0400 Subject: [PATCH 3/3] Fix issue with associations no using the module path. --- lib/jsonapi/association.rb | 3 ++- lib/jsonapi/resource.rb | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/jsonapi/association.rb b/lib/jsonapi/association.rb index bcc98b115..8704d0a2f 100644 --- a/lib/jsonapi/association.rb +++ b/lib/jsonapi/association.rb @@ -7,10 +7,11 @@ def initialize(name, options={}) @options = options @acts_as_set = options.fetch(:acts_as_set, false) == true @foreign_key = options[:foreign_key ] ? options[:foreign_key ].to_sym : nil + @module_path = options[:module_path] || '' end def primary_key - @primary_key ||= Resource.resource_for(@name)._primary_key + @primary_key ||= Resource.resource_for(@module_path + @name)._primary_key end class HasOne < Association diff --git a/lib/jsonapi/resource.rb b/lib/jsonapi/resource.rb index 035ce34b6..515ca5a44 100644 --- a/lib/jsonapi/resource.rb +++ b/lib/jsonapi/resource.rb @@ -127,7 +127,7 @@ def _create_has_many_links(association_type, association_key_values) association = self.class._associations[association_type] association_key_values.each do |association_key_value| - related_resource = Resource.resource_for(association.type).find_by_key(association_key_value, context: @context) + related_resource = Resource.resource_for(self.class.module_path + association.type.to_s).find_by_key(association_key_value, context: @context) # ToDo: Add option to skip relations that already exist instead of returning an error? relation = @model.send(association.type).where(association.primary_key => association_key_value).first @@ -515,6 +515,7 @@ def check_reserved_association_name(name) def _associate(klass, *attrs) options = attrs.extract_options! + options[:module_path] = module_path attrs.each do |attr| check_reserved_association_name(attr)