Skip to content

Commit

Permalink
Fix issue with associations no using the module path.
Browse files Browse the repository at this point in the history
  • Loading branch information
lgebhardt committed Apr 6, 2015
1 parent 900d23b commit 875a81b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
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
3 changes: 2 additions & 1 deletion 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 @@ -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)
Expand Down

0 comments on commit 875a81b

Please sign in to comment.