File tree Expand file tree Collapse file tree 3 files changed +21
-2
lines changed Expand file tree Collapse file tree 3 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ export default class Model {
28
28
static isJWTOwner : boolean = false ;
29
29
static jwt : string = null ;
30
30
static parentClass : typeof Model ;
31
+ static camelizeKeys : boolean = true ;
31
32
32
33
id : string ;
33
34
temp_id : string ;
@@ -209,7 +210,12 @@ export default class Model {
209
210
210
211
assignAttributes ( attrs : Object ) {
211
212
for ( var key in attrs ) {
212
- let attributeName = camelize ( key ) ;
213
+ let attributeName = key ;
214
+
215
+ if ( this . klass . camelizeKeys ) {
216
+ attributeName = camelize ( key ) ;
217
+ }
218
+
213
219
if ( key == 'id' || this . klass . attributeList [ attributeName ] ) {
214
220
this [ attributeName ] = attrs [ key ] ;
215
221
}
Original file line number Diff line number Diff line change @@ -18,6 +18,12 @@ class PersonWithExtraAttr extends Person {
18
18
extraThing : string = attr ( { persist : false } ) ;
19
19
}
20
20
21
+ class PersonWithoutCamelizedKeys extends Person {
22
+ static camelizeKeys = false ;
23
+
24
+ first_name : string = attr ( ) ;
25
+ }
26
+
21
27
// Ensure setup() can be run multiple times with no problems
22
28
// putting this here, otherwise relations wont be available.
23
29
Config . setup ( ) ;
@@ -95,6 +101,7 @@ export {
95
101
Author ,
96
102
Person ,
97
103
PersonWithExtraAttr ,
104
+ PersonWithoutCamelizedKeys ,
98
105
Book ,
99
106
Genre ,
100
107
Bio ,
Original file line number Diff line number Diff line change 1
1
import { sinon , expect } from '../test-helper' ;
2
- import { Person , Author } from '../fixtures' ;
2
+ import { Person , Author , PersonWithoutCamelizedKeys } from '../fixtures' ;
3
3
4
4
describe ( 'Model attributes' , function ( ) {
5
5
it ( 'supports direct assignment' , function ( ) {
@@ -20,6 +20,12 @@ describe('Model attributes', function() {
20
20
expect ( person . firstName ) . to . eq ( 'Joe' ) ;
21
21
} ) ;
22
22
23
+ it ( 'does not camlize underscored strings if camelization is disabled' , function ( ) {
24
+ let person = new PersonWithoutCamelizedKeys ( { first_name : 'Joe' } ) ;
25
+ expect ( person . firstName ) . to . eq ( undefined ) ;
26
+ expect ( person . first_name ) . to . eq ( 'Joe' ) ;
27
+ } )
28
+
23
29
it ( 'syncs with #attributes' , function ( ) {
24
30
let person = new Person ( ) ;
25
31
expect ( person . attributes ) . to . eql ( { } ) ;
You can’t perform that action at this time.
0 commit comments