File tree Expand file tree Collapse file tree 2 files changed +40
-2
lines changed Expand file tree Collapse file tree 2 files changed +40
-2
lines changed Original file line number Diff line number Diff line change @@ -309,9 +309,10 @@ def _build_connection(rebuild = false)
309309 #
310310 # @param params [Hash] Attributes, links, and relationships
311311 def initialize ( params = { } )
312+ params = params . symbolize_keys
312313 @persisted = nil
313- self . links = self . class . linker . new ( params . delete ( " links" ) || { } )
314- self . relationships = self . class . relationship_linker . new ( self . class , params . delete ( " relationships" ) || { } )
314+ self . links = self . class . linker . new ( params . delete ( : links) || { } )
315+ self . relationships = self . class . relationship_linker . new ( self . class , params . delete ( : relationships) || { } )
315316 self . attributes = self . class . default_attributes . merge ( params )
316317
317318 self . class . schema . each_property do |property |
Original file line number Diff line number Diff line change @@ -271,4 +271,41 @@ def test_callbacks_on_update
271271 assert_equal 100 , callback_test . bar
272272 end
273273
274+ def test_create_with_relationships_in_payload
275+ stub_request ( :post , 'http://example.com/articles' )
276+ . with ( headers : { content_type : 'application/vnd.api+json' , accept : 'application/vnd.api+json' } , body : {
277+ data : {
278+ type : 'articles' ,
279+ attributes : {
280+ title : 'Rails is Omakase'
281+ } ,
282+ relationships : {
283+ comments : {
284+ data : [
285+ {
286+ id : '2' ,
287+ type : 'comments'
288+ }
289+ ]
290+ }
291+ }
292+ }
293+ } . to_json )
294+ . to_return ( headers : { content_type : 'application/vnd.api+json' } , body : {
295+ data : {
296+ type : 'articles' ,
297+ id : '1' ,
298+ attributes : {
299+ title : 'Rails is Omakase'
300+ }
301+ }
302+ } . to_json )
303+
304+ article = Article . new ( title : 'Rails is Omakase' , relationships : { comments : [ Comment . new ( id : 2 ) ] } )
305+
306+ assert article . save
307+ assert article . persisted?
308+ assert_equal "1" , article . id
309+ end
310+
274311end
You can’t perform that action at this time.
0 commit comments