findOrCreate true/false


I use method findOrCreate({data_find}, {data_create}) when create new record to database but problem is how (easy way) check is record already exist instead only returning data from database or new data that created?

I found on sequelize this snippet:

  .findOrCreate({where: {username: 'sdepold'}, defaults: {job: 'Technical Lead JavaScript'}})
  .spread(function(user, created) {  **// <<< this one missing in Adonis**
      plain: true

        username: 'sdepold',
        job: 'Technical Lead JavaScript',
        id: 1,
        createdAt: Fri Mar 22 2013 21: 28: 34 GMT + 0100(CET),
        updatedAt: Fri Mar 22 2013 21: 28: 34 GMT + 0100(CET)
      created: true

Here we have all data that we find or create and also created true/false.

I think this would make good proposal to v5 if it’s not in there already :slight_smile:

1 Like