lib/jsonapi/relationship.rb in jsonapi-resources-0.7.1.beta2 vs lib/jsonapi/relationship.rb in jsonapi-resources-0.8.0.beta1

- old
+ new

@@ -1,20 +1,21 @@ module JSONAPI class Relationship attr_reader :acts_as_set, :foreign_key, :options, :name, :class_name, :polymorphic, :always_include_linkage_data, - :parent_resource + :parent_resource, :eager_load_on_include def initialize(name, options = {}) @name = name.to_s @options = options @acts_as_set = options.fetch(:acts_as_set, false) == true @foreign_key = options[:foreign_key] ? options[:foreign_key].to_sym : nil @parent_resource = options[:parent_resource] @relation_name = options.fetch(:relation_name, @name) @polymorphic = options.fetch(:polymorphic, false) == true @always_include_linkage_data = options.fetch(:always_include_linkage_data, false) == true + @eager_load_on_include = options.fetch(:eager_load_on_include, true) == true end alias_method :polymorphic?, :polymorphic def primary_key @@ -72,18 +73,22 @@ def belongs_to? foreign_key_on == :self end def polymorphic_type - "#{type.to_s.singularize}_type" if polymorphic? + "#{name}_type" if polymorphic? end end class ToMany < Relationship + attr_reader :reflect, :inverse_relationship + def initialize(name, options = {}) super @class_name = options.fetch(:class_name, name.to_s.camelize.singularize) @foreign_key ||= "#{name.to_s.singularize}_ids".to_sym + @reflect = options.fetch(:reflect, true) == true + @inverse_relationship = options.fetch(:inverse_relationship, parent_resource._type.to_s.singularize.to_sym) if parent_resource end end end end