Skip to content

Commit 380d6f4

Browse files
jaumardjaumard
authored andcommitted
add insensitive model association match
1 parent 1b9ce87 commit 380d6f4

File tree

3 files changed

+248
-1531
lines changed

3 files changed

+248
-1531
lines changed

api/services/FootprintService.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,11 @@ module.exports = class FootprintService extends Service {
204204
return query.catch(manageError)
205205
}
206206

207+
_findNativeAssociation(model, childAttributeName) {
208+
return model.associations[childAttributeName] ||
209+
model.associations[childAttributeName.charAt(0).toUpperCase() + childAttributeName.slice(1)]
210+
}
211+
207212
/**
208213
* Create a model, and associate it with its parent model.
209214
*
@@ -219,7 +224,7 @@ module.exports = class FootprintService extends Service {
219224
if (!parentModel) {
220225
return Promise.reject(new ModelError('E_NOT_FOUND', `${parentModelName} can't be found`))
221226
}
222-
const association = parentModel.associations[childAttributeName]
227+
const association = this._findNativeAssociation(parentModel, childAttributeName)
223228
if (!association) {
224229
return Promise.reject(new ModelError('E_NOT_FOUND', `${parentModelName}'s association ${childAttributeName} can't be found`))
225230
}
@@ -272,7 +277,7 @@ module.exports = class FootprintService extends Service {
272277
if (!parentModel) {
273278
return Promise.reject(new ModelError('E_NOT_FOUND', `${parentModelName} can't be found`))
274279
}
275-
const association = parentModel.associations[childAttributeName]
280+
const association = this._findNativeAssociation(parentModel, childAttributeName)
276281
if (!association) {
277282
return Promise.reject(new ModelError('E_NOT_FOUND', `${parentModelName}'s association ${childAttributeName} can't be found`))
278283
}
@@ -340,7 +345,7 @@ module.exports = class FootprintService extends Service {
340345
if (!parentModel) {
341346
return Promise.reject(new ModelError('E_NOT_FOUND', `${parentModelName} can't be found`))
342347
}
343-
const association = parentModel.associations[childAttributeName]
348+
const association = this._findNativeAssociation(parentModel, childAttributeName)
344349
if (!association) {
345350
return Promise.reject(new ModelError('E_NOT_FOUND', `${parentModelName}'s association ${childAttributeName} can't be found`))
346351
}

package.json

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "trailpack-sequelize",
3-
"version": "3.1.0",
3+
"version": "3.1.1",
44
"description": "Sequelize.js Trailpack http://sequelizejs.com",
55
"homepage": "https://github.com/jaumard/trailpack-sequelize",
66
"author": {
@@ -30,19 +30,18 @@
3030
],
3131
"dependencies": {
3232
"joi": "^12.0.0",
33-
"lodash": "^4.17.4",
33+
"lodash": "^4.17.5",
3434
"trailpack": "^3",
35-
"sequelize": "^4.29.3",
36-
"snyk": "^1.50.0"
35+
"sequelize": "^4.37.1"
3736
},
3837
"devDependencies": {
39-
"eslint": "^4.11.0",
40-
"eslint-config-trails": "^3.0.0",
41-
"mocha": "^4.0.1",
38+
"eslint": "^4.19.0",
39+
"eslint-config-trails": "^3.1.0",
40+
"mocha": "^5.0.4",
4241
"pre-commit": "^1.2.2",
4342
"smokesignals": "^3",
4443
"trails": "^3",
45-
"sqlite3": "^3.1.13"
44+
"sqlite3": "^4.0.0"
4645
},
4746
"peerDependencies": {
4847
"trails": "3.x"

0 commit comments

Comments
 (0)