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 {
2828 static isJWTOwner : boolean = false ;
2929 static jwt : string = null ;
3030 static parentClass : typeof Model ;
31+ static camelizeKeys : boolean = true ;
3132
3233 id : string ;
3334 temp_id : string ;
@@ -209,7 +210,12 @@ export default class Model {
209210
210211 assignAttributes ( attrs : Object ) {
211212 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+
213219 if ( key == 'id' || this . klass . attributeList [ attributeName ] ) {
214220 this [ attributeName ] = attrs [ key ] ;
215221 }
Original file line number Diff line number Diff line change @@ -18,6 +18,12 @@ class PersonWithExtraAttr extends Person {
1818 extraThing : string = attr ( { persist : false } ) ;
1919}
2020
21+ class PersonWithoutCamelizedKeys extends Person {
22+ static camelizeKeys = false ;
23+
24+ first_name : string = attr ( ) ;
25+ }
26+
2127// Ensure setup() can be run multiple times with no problems
2228// putting this here, otherwise relations wont be available.
2329Config . setup ( ) ;
@@ -95,6 +101,7 @@ export {
95101 Author ,
96102 Person ,
97103 PersonWithExtraAttr ,
104+ PersonWithoutCamelizedKeys ,
98105 Book ,
99106 Genre ,
100107 Bio ,
Original file line number Diff line number Diff line change 11import { sinon , expect } from '../test-helper' ;
2- import { Person , Author } from '../fixtures' ;
2+ import { Person , Author , PersonWithoutCamelizedKeys } from '../fixtures' ;
33
44describe ( 'Model attributes' , function ( ) {
55 it ( 'supports direct assignment' , function ( ) {
@@ -20,6 +20,12 @@ describe('Model attributes', function() {
2020 expect ( person . firstName ) . to . eq ( 'Joe' ) ;
2121 } ) ;
2222
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+
2329 it ( 'syncs with #attributes' , function ( ) {
2430 let person = new Person ( ) ;
2531 expect ( person . attributes ) . to . eql ( { } ) ;
You can’t perform that action at this time.
0 commit comments