Skip to content
Merged
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
8 changes: 5 additions & 3 deletions lib/jsonapi/relationship.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module JSONAPI
class Relationship
attr_reader :acts_as_set, :foreign_key, :type, :options, :name,
attr_reader :acts_as_set, :foreign_key, :options, :name,
:class_name, :polymorphic, :always_include_linkage_data,
:parent_resource

Expand Down Expand Up @@ -29,6 +29,10 @@ def table_name
@table_name ||= resource_klass._table_name
end

def type
@type ||= resource_klass._type.to_sym
end

def relation_name(options)
case @relation_name
when Symbol
Expand Down Expand Up @@ -61,7 +65,6 @@ class ToOne < Relationship
def initialize(name, options = {})
super
@class_name = options.fetch(:class_name, name.to_s.camelize)
@type = class_name.underscore.pluralize.to_sym
@foreign_key ||= "#{name}_id".to_sym
@foreign_key_on = options.fetch(:foreign_key_on, :self)
end
Expand All @@ -79,7 +82,6 @@ class ToMany < Relationship
def initialize(name, options = {})
super
@class_name = options.fetch(:class_name, name.to_s.camelize.singularize)
@type = class_name.underscore.pluralize.to_sym
@foreign_key ||= "#{name.to_s.singularize}_ids".to_sym
end
end
Expand Down