Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/jsonapi/association.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 2 additions & 6 deletions lib/jsonapi/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -520,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)
Expand Down
1 change: 0 additions & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down