File tree 1 file changed +15
-0
lines changed
1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change 1
1
'use strict'
2
2
3
3
var _ = require ( 'lodash' )
4
+ var utils = require ( './utils' )
4
5
5
6
function defaultBeforeDeserialize ( options , cb ) {
6
7
cb ( null , options )
@@ -79,6 +80,20 @@ function belongsToRelationships (options) {
79
80
options . result [ fkName ] = null
80
81
} else {
81
82
options . result [ fkName ] = relationship . data . id
83
+ if ( serverRelation . polymorphic ) {
84
+ // Find the model which has a plural matching 'data.type'
85
+ // Allow case insensitive match
86
+ var relatedType = relationship . data . type . toLowerCase ( )
87
+ var modelName = _ . findKey ( model . app . models , function ( model ) {
88
+ var plural = utils . pluralForModel ( model )
89
+ return plural . toLowerCase ( ) === relatedType
90
+ } )
91
+ if ( ! modelName ) {
92
+ return false
93
+ }
94
+ var discriminator = serverRelation . polymorphic . discriminator
95
+ options . result [ discriminator ] = modelName
96
+ }
82
97
}
83
98
} )
84
99
}
You can’t perform that action at this time.
0 commit comments