File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -572,6 +572,9 @@ class Document < ActiveRecord::Base
572572 has_many :pictures , as : :imageable
573573end
574574
575+ class Document ::Topic < Document
576+ end
577+
575578class Product < ActiveRecord ::Base
576579 has_one :picture , as : :imageable
577580end
@@ -1209,6 +1212,11 @@ class DocumentResource < JSONAPI::Resource
12091212 has_many :pictures
12101213end
12111214
1215+ class TopicResource < JSONAPI ::Resource
1216+ model_name 'Document::Topic'
1217+ has_many :pictures
1218+ end
1219+
12121220class ProductResource < JSONAPI ::Resource
12131221 attribute :name
12141222 has_one :picture , always_include_linkage_data : true
Original file line number Diff line number Diff line change @@ -205,6 +205,14 @@ def test_class_relationships
205205 assert_equal ( relationships . size , 2 )
206206 end
207207
208+ def test_replace_polymorphic_to_one_link
209+ picture_resource = PictureResource . find_by_key ( Picture . first )
210+ picture_resource . replace_polymorphic_to_one_link ( 'imageable' , '9' , 'Topic' )
211+
212+ assert Picture . first . imageable_id == 9
213+ assert Picture . first . imageable_type == Document ::Topic . to_s
214+ end
215+
208216 def test_duplicate_relationship_name
209217 assert_output nil , "[DUPLICATE RELATIONSHIP] `mother` has already been defined in CatResource.\n " do
210218 CatResource . instance_eval do
You can’t perform that action at this time.
0 commit comments