@@ -2081,6 +2081,77 @@ describe('JSONAPISerializer', function() {
20812081 done ( ) ;
20822082 } ) ;
20832083
2084+ it ( 'should deserializing relationship when alternativeKey is set and relationship data is not in the included array' , function ( done ) {
2085+ const Serializer = new JSONAPISerializer ( ) ;
2086+
2087+ Serializer . register ( 'article' , {
2088+ id : 'id' ,
2089+ relationships : {
2090+ author : {
2091+ type : 'people' ,
2092+ alternativeKey : 'author_id' ,
2093+ } ,
2094+ } ,
2095+ } ) ;
2096+
2097+ Serializer . register ( 'people' , {
2098+ id : 'id' ,
2099+ relationships : {
2100+ role : {
2101+ alternativeKey : 'role_id' ,
2102+ type : 'role' ,
2103+ } ,
2104+ } ,
2105+ } ) ;
2106+
2107+ Serializer . register ( 'role' , { } ) ;
2108+
2109+ const data = {
2110+ data : {
2111+ type : 'article' ,
2112+ id : '1' ,
2113+ attributes : {
2114+ title : 'JSON API paints my bikeshed!' ,
2115+ body : 'The shortest article. Ever.' ,
2116+ created : '2015-05-22T14:56:29.000Z' ,
2117+ } ,
2118+ relationships : {
2119+ author : {
2120+ data : {
2121+ type : 'people' ,
2122+ id : '1' ,
2123+ } ,
2124+ } ,
2125+ } ,
2126+ } ,
2127+ included : [
2128+ {
2129+ type : 'people' ,
2130+ id : '1' ,
2131+ attributes : {
2132+ firstName : 'Kaley' ,
2133+ lastName : 'Maggio' ,
2134+ } ,
2135+ relationships : {
2136+ role : {
2137+ data : {
2138+ type : 'role' ,
2139+ id : '1' ,
2140+ } ,
2141+ } ,
2142+ } ,
2143+ } ,
2144+ ] ,
2145+ } ;
2146+
2147+ const deserializedData = Serializer . deserialize ( 'article' , data ) ;
2148+ expect ( deserializedData ) . to . have . property ( 'author_id' ) . to . eql ( '1' ) ;
2149+ expect ( deserializedData ) . to . have . property ( 'author' ) ;
2150+ expect ( deserializedData . author ) . to . have . property ( 'role_id' ) . to . eql ( '1' ) ;
2151+ expect ( deserializedData . author ) . to . not . have . property ( 'role' ) ;
2152+ done ( ) ;
2153+ } ) ;
2154+
20842155 it ( 'should deserialize with \'deserialize\' option as a function' , function ( done ) {
20852156 const Serializer = new JSONAPISerializer ( ) ;
20862157 Serializer . register ( 'articles' , {
0 commit comments