@kaspernj/api-maker 1.0.123 → 1.0.124

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -16,7 +16,7 @@
16
16
  ]
17
17
  },
18
18
  "name": "@kaspernj/api-maker",
19
- "version": "1.0.123",
19
+ "version": "1.0.124",
20
20
  "description": "",
21
21
  "main": "index.js",
22
22
  "repository": {
@@ -145,6 +145,7 @@ module.exports = class ApiMakerModelRecipesModelLoader {
145
145
  modelMethodName,
146
146
  modelRecipesLoader,
147
147
  optionsAs,
148
+ optionsPrimaryKey,
148
149
  optionsThrough,
149
150
  relationshipName,
150
151
  resourceName
@@ -195,7 +196,7 @@ module.exports = class ApiMakerModelRecipesModelLoader {
195
196
  }
196
197
  }
197
198
 
198
- defineHasManyGetMethod({activeRecordName, className, foreignKey, ModelClass, modelMethodName, modelRecipesLoader, optionsAs, optionsThrough, relationshipName, resourceName}) {
199
+ defineHasManyGetMethod({activeRecordName, className, foreignKey, ModelClass, modelMethodName, modelRecipesLoader, optionsAs, optionsPrimaryKey, optionsThrough, relationshipName, resourceName}) {
199
200
  ModelClass.prototype[modelMethodName] = function () {
200
201
  const id = this.primaryKey()
201
202
  const modelClass = modelRecipesLoader.getModelClass(resourceName)
@@ -224,8 +225,12 @@ module.exports = class ApiMakerModelRecipesModelLoader {
224
225
  }
225
226
  } else {
226
227
  const ransack = {}
228
+ const primaryKeyColumnName = optionsPrimaryKey || digg(ModelClass.modelClassData(), "primaryKey")
229
+ const primaryKeyMethodName = inflection.camelize(primaryKeyColumnName, true)
230
+
231
+ if (!(primaryKeyMethodName in this)) throw new Error(`No such primary key method: ${primaryKeyMethodName}`)
227
232
 
228
- ransack[`${foreignKey}_eq`] = this.primaryKey()
233
+ ransack[`${foreignKey}_eq`] = this[primaryKeyMethodName]()
229
234
 
230
235
  if (optionsAs) {
231
236
  ransack[`${optionsAs}_type_eq`] = activeRecordName