Skip to content

Commit

Permalink
Fix missing Objection Id columns (#61)
Browse files Browse the repository at this point in the history
It was spotted whilst working on [Update "create bill run" endpoint to create a bill run](#56) that we had an issue with our [Objection models](https://vincit.github.io/objection.js/).

The previous team didn't use the convention of just calling the unique identifier in each table `id`. Instead, they incorporate the table name, for example, `billing_batch_id`. **Objection** is expecting the identifier column to be `id` and is failing when in some cases.

Because of this, we need to go back and specify [idColumn](https://vincit.github.io/objection.js/api/model/static-properties.html#static-idcolumn) in all our models.
  • Loading branch information
Cruikshanks authored Dec 19, 2022
1 parent 28c5cb5 commit 6d4c9be
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/models/billing-batch.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ class BillingBatchModel extends BaseModel {
return 'water.billing_batches'
}

static get idColumn () {
return 'billing_batch_id'
}

static get relationMappings () {
return {
region: {
Expand Down
4 changes: 4 additions & 0 deletions app/models/billing-charge-category.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ class BillingChargeCategoryModel extends BaseModel {
return 'water.billing_charge_categories'
}

static get idColumn () {
return 'billing_charge_category_id'
}

static get relationMappings () {
return {
chargeElement: {
Expand Down
4 changes: 4 additions & 0 deletions app/models/charge-element.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ class ChargeElementModel extends BaseModel {
return 'water.charge_elements'
}

static get idColumn () {
return 'charge_element_id'
}

static get relationMappings () {
return {
chargeVersion: {
Expand Down
4 changes: 4 additions & 0 deletions app/models/charge-purpose.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ class ChargePurposeModel extends BaseModel {
return 'water.charge_purposes'
}

static get idColumn () {
return 'charge_purpose_id'
}

static get relationMappings () {
return {
chargeElement: {
Expand Down
4 changes: 4 additions & 0 deletions app/models/charge-version.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ class ChargeVersionModel extends BaseModel {
return 'water.charge_versions'
}

static get idColumn () {
return 'charge_version_id'
}

static get relationMappings () {
return {
licence: {
Expand Down
4 changes: 4 additions & 0 deletions app/models/event.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ class EventModel extends BaseModel {
static get tableName () {
return 'water.events'
}

static get idColumn () {
return 'event_id'
}
}

module.exports = EventModel
4 changes: 4 additions & 0 deletions app/models/licence.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ class LicenceModel extends BaseModel {
return 'water.licences'
}

static get idColumn () {
return 'licence_id'
}

static get relationMappings () {
return {
chargeVersions: {
Expand Down
4 changes: 4 additions & 0 deletions app/models/region.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ class RegionModel extends BaseModel {
return 'water.regions'
}

static get idColumn () {
return 'region_id'
}

static get relationMappings () {
return {
licences: {
Expand Down

0 comments on commit 6d4c9be

Please sign in to comment.