Skip to content

Commit 23195aa

Browse files
committed
Merge pull request #695 from cerebris/relation_type
Load type based on resource_klass's type and not the class_name.
2 parents f4ab568 + 20997a2 commit 23195aa

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

lib/jsonapi/relationship.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module JSONAPI
22
class Relationship
3-
attr_reader :acts_as_set, :foreign_key, :type, :options, :name,
3+
attr_reader :acts_as_set, :foreign_key, :options, :name,
44
:class_name, :polymorphic, :always_include_linkage_data,
55
:parent_resource
66

@@ -29,6 +29,10 @@ def table_name
2929
@table_name ||= resource_klass._table_name
3030
end
3131

32+
def type
33+
@type ||= resource_klass._type.to_sym
34+
end
35+
3236
def relation_name(options)
3337
case @relation_name
3438
when Symbol
@@ -61,7 +65,6 @@ class ToOne < Relationship
6165
def initialize(name, options = {})
6266
super
6367
@class_name = options.fetch(:class_name, name.to_s.camelize)
64-
@type = class_name.underscore.pluralize.to_sym
6568
@foreign_key ||= "#{name}_id".to_sym
6669
@foreign_key_on = options.fetch(:foreign_key_on, :self)
6770
end
@@ -79,7 +82,6 @@ class ToMany < Relationship
7982
def initialize(name, options = {})
8083
super
8184
@class_name = options.fetch(:class_name, name.to_s.camelize.singularize)
82-
@type = class_name.underscore.pluralize.to_sym
8385
@foreign_key ||= "#{name.to_s.singularize}_ids".to_sym
8486
end
8587
end

0 commit comments

Comments
 (0)