Skip to content

Commit 6a25bee

Browse files
authored
Merge pull request #1003 from dougo/add-multiple-relationships-at-once
Bug fix: Allow multiple relationships to be defined in one declaration.
2 parents f8606fb + 42da412 commit 6a25bee

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

lib/jsonapi/resource.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ def define_relationship_methods(relationship_name, relationship_klass, options)
917917
if _model_class && _model_class.ancestors.collect { |ancestor| ancestor.name }.include?('ActiveRecord::Base')
918918
model_association = _model_class.reflect_on_association(relationship_name)
919919
if model_association
920-
options[:class_name] ||= model_association.class_name
920+
options = options.reverse_merge(class_name: model_association.class_name)
921921
end
922922
end
923923

test/fixtures/active_record.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -936,8 +936,7 @@ class PersonResource < BaseResource
936936
attributes :name, :email
937937
attribute :date_joined, format: :date_with_timezone
938938

939-
has_many :comments
940-
has_many :posts
939+
has_many :comments, :posts
941940
has_many :vehicles, polymorphic: true
942941

943942
has_one :preferences

0 commit comments

Comments
 (0)