Skip to content

Commit d6ec56e

Browse files
committed
Merge pull request #148 from cerebris/name_map_fix
Fix issues with resource module path
2 parents e39c9c4 + 875a81b commit d6ec56e

File tree

3 files changed

+4
-8
lines changed

3 files changed

+4
-8
lines changed

Diff for: lib/jsonapi/association.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ def initialize(name, options={})
77
@options = options
88
@acts_as_set = options.fetch(:acts_as_set, false) == true
99
@foreign_key = options[:foreign_key ] ? options[:foreign_key ].to_sym : nil
10+
@module_path = options[:module_path] || ''
1011
end
1112

1213
def primary_key
13-
@primary_key ||= Resource.resource_for(@name)._primary_key
14+
@primary_key ||= Resource.resource_for(@module_path + @name)._primary_key
1415
end
1516

1617
class HasOne < Association

Diff for: lib/jsonapi/resource.rb

+2-6
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def _create_has_many_links(association_type, association_key_values)
127127
association = self.class._associations[association_type]
128128

129129
association_key_values.each do |association_key_value|
130-
related_resource = Resource.resource_for(association.type).find_by_key(association_key_value, context: @context)
130+
related_resource = Resource.resource_for(self.class.module_path + association.type.to_s).find_by_key(association_key_value, context: @context)
131131

132132
# ToDo: Add option to skip relations that already exist instead of returning an error?
133133
relation = @model.send(association.type).where(association.primary_key => association_key_value).first
@@ -203,11 +203,6 @@ def inherited(base)
203203
base.attribute :id, format: :id
204204

205205
check_reserved_resource_name(base._type, base.name)
206-
207-
# If eager loading is on this is how all the resource types are setup
208-
# If eager loading is off some resource types will be initialized in
209-
# _resource_name_from_type
210-
@@resource_types[base._type] ||= base.name.demodulize
211206
end
212207

213208
def resource_for(type)
@@ -518,6 +513,7 @@ def check_reserved_association_name(name)
518513

519514
def _associate(klass, *attrs)
520515
options = attrs.extract_options!
516+
options[:module_path] = module_path
521517

522518
attrs.each do |attr|
523519
check_reserved_association_name(attr)

Diff for: test/test_helper.rb

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
puts "Testing With RAILS VERSION #{Rails.version}"
2828

2929
class TestApp < Rails::Application
30-
config.eager_load = false
3130
config.root = File.dirname(__FILE__)
3231
config.session_store :cookie_store, key: 'session'
3332
config.secret_key_base = 'secret'

0 commit comments

Comments
 (0)