Coder Social home page Coder Social logo

Comments (6)

tjwebb avatar tjwebb commented on August 15, 2024

Thanks for the report, I'll look into it.

from sails-permissions.

tjwebb avatar tjwebb commented on August 15, 2024

What adapter are you using? It does attempt to create duplicate, but should just ignore the error.

btw, I think findOrCreate is going to be deprecated. Since this is a one-time operation, I'll just check for existence first

from sails-permissions.

tomhallam avatar tomhallam commented on August 15, 2024

Using the stock mongodb adapter.

Findorcreate is far from perfect but I think it's valuable, can you link me
to deprecation thread?

~T
On 25 Feb 2015 20:29, "Travis Webb" [email protected] wrote:

What adapter are you using? It does attempt to create duplicate, but
should just ignore the error.

btw, I think findOrCreate is going to be deprecated

β€”
Reply to this email directly or view it on GitHub
#19 (comment)
.

from sails-permissions.

tjwebb avatar tjwebb commented on August 15, 2024

balderdashy/waterline#843

Check the latest release. I check for existence before creating the models.

from sails-permissions.

heygrady avatar heygrady commented on August 15, 2024

Fresh install of [email protected] and [email protected]. Getting errors after restarting sails because the fixtures have already created all of my records. Using [email protected].

I was able to fix it by wrapping the create calls in a findOne.

In sails-permissions/config/fixtures/model.js

exports.createModels = function () {
  sails.log('Installing Models');

  var models = _.compact(_.map(sails.controllers, function (controller, name) {
    var model = sails.models[name];
    return model && model.globalId && model.identity && {
      name: model.globalId,
      identity: model.identity,
      attributes: _.omit(model.attributes, _.functions(model.attributes))
    };
  }));

  return Promise.map(models, function (model) {
    sails.log('creating', model.name);
    // return Model.create(model);
    // wrap the `create` in a `findOne` to check for existence
    return Model.findOne({ name: model.name }).then(function(existing) { return existing || Model.create(model); });
  });
};

In sails-permissions/config/fixtures/role.js

exports.create = function () {
  return Promise.all([
    Role.findOne({ name: 'admin' }).then(function(existing) { return existing || Role.create({ name: 'admin' }); }),
    Role.findOne({ name: 'registered' }).then(function(existing) { return existing || Role.create({ name: 'registered' }); }),
    Role.findOne({ name: 'public' }).then(function(existing) { return existing || Role.create({ name: 'public' }); })
  ]);
};

from sails-permissions.

tjwebb avatar tjwebb commented on August 15, 2024

The unit tests use sails-disk so I missed this one for awhile

from sails-permissions.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.