@@ -8,6 +8,7 @@ process.env.NODE_ENV = 'test';
88require ( 'should' ) ;
99
1010const assert = require ( 'assert' ) ;
11+ const should = require ( 'should' ) ;
1112const _ = require ( 'lodash' ) ;
1213
1314const DataSource = require ( 'loopback-datasource-juggler' ) . DataSource ;
@@ -239,6 +240,36 @@ describe('Discover model properties', function() {
239240} ) ;
240241
241242describe ( 'Discover model primary keys' , function ( ) {
243+ let Demo ;
244+ before ( function ( done ) {
245+ const demo_schema = {
246+ 'name' : 'Demo' ,
247+ 'options' : {
248+ 'idInjection' : false ,
249+ 'postgresql' : {
250+ 'schema' : 'public' ,
251+ 'table' : 'demo' ,
252+ } ,
253+ } ,
254+ 'properties' : {
255+ 'id' : {
256+ 'type' : 'Number' ,
257+ 'required' : true ,
258+ 'id' : 1 ,
259+ 'postgresql' : {
260+ 'columnName' : 'demoId' ,
261+ } ,
262+ } ,
263+ 'name' : {
264+ 'type' : 'String' ,
265+ 'required' : true ,
266+ } ,
267+ } ,
268+ } ;
269+ Demo = db . createModel ( demo_schema . name , demo_schema . properties , demo_schema . options ) ;
270+ Demo . destroyAll ( done ) ;
271+ } ) ;
272+
242273 it ( 'should return an array of primary keys for product' , function ( done ) {
243274 db . discoverPrimaryKeys ( 'product' , function ( err , models ) {
244275 if ( err ) {
@@ -257,6 +288,32 @@ describe('Discover model primary keys', function() {
257288 } ) ;
258289 } ) ;
259290
291+ it ( 'should discover primary key and db generates instances properly' , function ( done ) {
292+ db . discoverPrimaryKeys ( 'demo' , function ( err , models ) {
293+ if ( err ) {
294+ console . error ( err ) ;
295+ done ( err ) ;
296+ } else {
297+ models . length . should . be . equal ( 1 ) ;
298+ assert . deepEqual ( models [ 0 ] , { owner : 'public' ,
299+ tableName : 'demo' ,
300+ columnName : 'demoId' ,
301+ keySeq : 1 ,
302+ pkName : 'demo_pkey' } ) ;
303+ }
304+ } ) ;
305+ Demo . create ( { id : 1 , name : 'checkCase' } , function ( err ) {
306+ should . not . exist ( err ) ;
307+ Demo . findOne ( { } , function ( err , d ) {
308+ should . not . exist ( err ) ;
309+ should . exist ( d ) ;
310+ d . should . have . property ( 'id' , 1 ) ;
311+ d . should . have . property ( 'name' , 'checkCase' ) ;
312+ done ( ) ;
313+ } ) ;
314+ } ) ;
315+ } ) ;
316+
260317 it ( 'should return an array of primary keys for strongloop.product' , function ( done ) {
261318 db . discoverPrimaryKeys ( 'product' , { owner : 'strongloop' } , function ( err , models ) {
262319 if ( err ) {
0 commit comments