2013-07-12 13 views
5

Quindi mi trovo in giro con SailsJS per cercare di ottenere un'API attiva e veloce. Non ho ancora installato un data store (probabilmente userò mongodb) ma ho visto che c'è quello che presumo sia come un database SQLite o qualcosa del genere. Così ho generato un modello e un controller per un utente. Quindi nel browser ho colpito l'utente/creare. Vedo createAt e updatedAt ma nessun Id. Ho bisogno di un vero datastore per vedere un ID? È ancora qualcosa che ottieni gratis?ID non visibile in vele Risposta JS

adattatore

// Configure installed adapters 
// If you define an attribute in your model definition, 
// it will override anything from this global config. 
module.exports.adapters = { 

    // If you leave the adapter config unspecified 
    // in a model definition, 'default' will be used. 
    'default': 'disk', 

    // In-memory adapter for DEVELOPMENT ONLY 
    // (data is NOT preserved when the server shuts down) 
    memory: { 
     module: 'sails-dirty', 
     inMemory: true 
    }, 

    // Persistent adapter for DEVELOPMENT ONLY 
    // (data IS preserved when the server shuts down) 
    // PLEASE NOTE: disk adapter not compatible with node v0.10.0 currently 
    //    because of limitations in node-dirty 
    //    See https://github.com/felixge/node-dirty/issues/34 
    disk: { 
     module: 'sails-dirty', 
     filePath: './.tmp/dirty.db', 
     inMemory: false 
    }, 

    // MySQL is the world's most popular relational database. 
    // Learn more: http://en.wikipedia.org/wiki/MySQL 
    mysql: { 
     module  : 'sails-mysql', 
     host  : 'YOUR_MYSQL_SERVER_HOSTNAME_OR_IP_ADDRESS', 
     user  : 'YOUR_MYSQL_USER', 
     password : 'YOUR_MYSQL_PASSWORD', 
     database : 'YOUR_MYSQL_DB' 
    } 
}; 

Modello

/*--------------------- 
    :: User 
    -> model 
---------------------*/ 
module.exports = { 

    attributes: { 
     firstName: 'STRING', 
     lastName: 'STRING' 
    } 

}; 
+0

Prova ad aggiungere questo al tuo modello. 'autoPk: true,' – Travis

risposta

0

Do .../user/findAll per elencare tutti gli utenti. Ogni utente dovrebbe avere una proprietà "id", ad es.

{ 
    "username":"admin", 
    "password":"$2a$10$SP/hWtlJINkMgkAuAc9bxO1iWsvVcglwEU4ctGCiYpx.7ykaFWt56", 
    "createdAt":"2013-07-12T17:36:29.852Z", 
    "updatedAt":"2013-07-12T17:36:29.852Z", 
    "id":1 
} 
+0

Non vedendolo. Di seguito è tutto ciò che vedo. '[{" firstName ":" Chad "," createdAt ":" 2013-07-12T04: 13: 16.917Z "," updatedAt ":" 2013-07-12T04: 13: 16.917Z "}, {" firstName ":" Chad", "lastName": "Hietala", "createdAt": "2013-07-12T04: 13: 33.538Z", "updatedAt": "2013-07-12T04: 13: 33.538Z"}, { "createdAt": "2013-07-12T04: 15: 44.243Z", "updatedAt": "2013-07-12T04: 15: 44.243Z"}, { "createdAt": "2013-07-12T04: 15: 47.704Z " "updatedAt": "2013-07-12T04: 15: 47.704Z"}, { "createdAt": "2013-07-12T04: 16: 15.506Z", "updatedAt":" 2013-07-12T04 : 16: 15.506Z "}]' – Chad

+0

/config/adapters.js configura il DB utilizzato. Ottengo una proprietà 'id' con entrambi 'default: "disk"' e 'default: "memoria"'. Puoi pubblicare i tuoi /config/adapters.js e /api/models.User.js? – JohnSz

+0

Inoltre: fa .../user/find/1 mostra il primo utente? Provalo con un altro. – JohnSz

0

ho checkout questo passando tra i diversi DB in una stessa applicazione vele e il suo lavoro assolutamente bene .

così in questo caso è possibile aggiungere una proprietà di autoPK al modello e l'impostazione su true come segue:

module.exports = { 
    attribute:{ 
     //your model attributes with validations. 
    }, 
    autoPK:true 
} 

non se questo non funziona per voi, allora penso che ci sia qualcosa che non va con il tuo copia delle vele installate sul tuo sistema.

Si prega di provare ad installare la versione più recente (v0.9.8) di vele utilizzando npm o provare ad aggiornare il pacchetto. Json con la versione più recente (v0.9.8) dettagli e installazione di nscute excute.

Problemi correlati