1+ var _ = require ( 'lodash' ) ;
12var should = require ( 'should' ) ;
23var helper = require ( '../support/spec_helper' ) ;
34var common = require ( '../common' ) ;
45var ORM = require ( '../../' ) ;
6+ var protocol = common . protocol ( ) ;
57
68describe ( "Model.get()" , function ( ) {
79 var db = null ;
@@ -11,7 +13,7 @@ describe("Model.get()", function() {
1113 var setup = function ( cache ) {
1214 return function ( done ) {
1315 Person = db . define ( "person" , {
14- name : String
16+ name : { type : 'text' , mapsTo : 'fullname' }
1517 } , {
1618 cache : cache ,
1719 methods : {
@@ -49,6 +51,33 @@ describe("Model.get()", function() {
4951 return db . close ( ) ;
5052 } ) ;
5153
54+ describe ( "mapsTo" , function ( ) {
55+ if ( protocol == 'mongodb' ) return ;
56+
57+ before ( setup ( true ) ) ;
58+
59+ it ( "should create the table with a different column name than property name" , function ( done ) {
60+ var sql ;
61+
62+ if ( protocol == 'sqlite' ) {
63+ sql = "PRAGMA table_info(?)" ;
64+ } else {
65+ sql = "SELECT column_name FROM information_schema.columns WHERE table_name = ?" ;
66+ }
67+
68+ db . driver . execQuery ( sql , [ Person . table ] , function ( err , data ) {
69+ should . not . exist ( err ) ;
70+
71+ var names = _ . pluck ( data , protocol == 'sqlite' ? 'name' : 'column_name' )
72+
73+ should . equal ( typeof Person . properties . name , 'object' ) ;
74+ should . notEqual ( names . indexOf ( 'fullname' ) , - 1 ) ;
75+
76+ done ( ) ;
77+ } ) ;
78+ } ) ;
79+ } ) ;
80+
5281 describe ( "with cache" , function ( ) {
5382 before ( setup ( true ) ) ;
5483
0 commit comments