@@ -130,10 +130,16 @@ export default class KnexProcessor<ResourceT extends Resource> extends Operation
130
130
const { id } = op . ref ;
131
131
const primaryKeyName = this . resourceClass . schema . primaryKeyName || DEFAULT_PRIMARY_KEY ;
132
132
133
+ const dataToUpdate = Object . keys ( op . data . attributes )
134
+ . map ( attribute => ( {
135
+ [ this . appInstance . app . serializer . attributeToColumn ( attribute ) ] : op . data . attributes [ attribute ]
136
+ } ) )
137
+ . reduce ( ( keyValues , keyValue ) => ( { ...keyValues , ...keyValue } ) , { } ) ;
138
+
133
139
const updated = await this . getQuery ( )
134
140
. where ( { [ primaryKeyName ] : id } )
135
141
. first ( )
136
- . update ( op . data . attributes ) ;
142
+ . update ( dataToUpdate ) ;
137
143
138
144
if ( ! updated ) {
139
145
throw JsonApiErrors . RecordNotExists ( ) ;
@@ -147,7 +153,14 @@ export default class KnexProcessor<ResourceT extends Resource> extends Operation
147
153
148
154
async add ( op : Operation ) : Promise < HasId > {
149
155
const primaryKeyName = this . resourceClass . schema . primaryKeyName || DEFAULT_PRIMARY_KEY ;
150
- const ids = await this . getQuery ( ) . insert ( op . data . attributes , primaryKeyName ) ;
156
+
157
+ const dataToInsert = Object . keys ( op . data . attributes )
158
+ . map ( attribute => ( {
159
+ [ this . appInstance . app . serializer . attributeToColumn ( attribute ) ] : op . data . attributes [ attribute ]
160
+ } ) )
161
+ . reduce ( ( keyValues , keyValue ) => ( { ...keyValues , ...keyValue } ) , { } ) ;
162
+
163
+ const ids = await this . getQuery ( ) . insert ( dataToInsert , primaryKeyName ) ;
151
164
152
165
return await this . getQuery ( )
153
166
. whereIn ( primaryKeyName , ids )
0 commit comments