问题
When i create a new record using Waterline's create method, the created object is returned, but without it's ID. How can I get the id of the last inserted object?
I'm using the mysql adapter on mariadb if it makes any difference
回答1:
It seems like you're probably doing something wrong. I have not done any additional configuration to waterline, anyway it returns id
every time when I use new
query as well as record at all.
In most cases I don't create id
field in sails model, auto-generation works quite fine for me. If you create id
field by yourself ensure that it has correct configuration. This issue shows that id requires to be
autoIncrement: true
otherwise it really don't return id with queries.
Full field should look like this:
id: {
type: 'integer',
primaryKey: true,
autoIncrement: true
}
来源:https://stackoverflow.com/questions/28103271/when-i-use-waterlines-create-method-it-doesnt-return-the-new-records-id