Scope applies to find but not create during findOrCreate call
See original GitHub issueRight now I’ve got a scoped Model and am trying to do a Model#findOrCreate()
on a table with two fields: name
and category
. category
is scoped on the model to always be a specific value for the file I’m in, and I’m trying to do bulk find/creates for several different values.
From looking through the code, it looks like the findOne
call is getting the scoped values, but the create is not. Values are inserted into the table without the scope values, which means a second findOrCreate
will create a duplicate entry
Here’s a quick example:
var Model = require('./myModel');
Model.scope('cats').findOrCreate( { where: { name: 'Cheshire' } } ).then(function () {
// Will create a second instance in the DB
Model.scope('cats').findOrCreate( { where: { name: 'Cheshire' } } );
});
Issue Analytics
- State:
- Created 8 years ago
- Reactions:1
- Comments:12 (3 by maintainers)
Top Results From Across the Web
Find or Create with Eloquent - Stack Overflow
Put this in any model and use // Modelname::findOrCreate($id); public static ... so the method in the Model will be scopeMethodName and call...
Read more >Model Querying - Finders - Sequelize
Finder methods are the ones that generate SELECT queries. ... The method findOrCreate will create an entry in the table unless it can...
Read more >sequelize.Model.findOrCreate JavaScript and Node.js code ...
Find a row that matches the query, or build and save the row if none is found The successful result of the promise...
Read more >Live agent does not create Contact neither Case
Hi all, I have a big problem, hope someone can help me. I successfully configured Live agent in a salesforce production org.
Read more >The Comprehensive Sequelize Cheatsheet
Things I did not include in this Cheatsheet (with links to official ... To set up a basic model with only attributes and...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Any updates on this bug?
@callmekatootie
Reloading the instance returned from
findOrCreate
seems to apply the defaultScope