Use absolute paths for relations in legacy models #562
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
https://eaflood.atlassian.net/browse/WATER-4057
As part of the work we have been doing on two-part tariff we are going to be creating all our new tables in the default
public
schema.We have also decided that when there is a legacy table that we are still going to need we will create a View of it in the
public
schema. This allows us to correct any issues with naming conventions, strip out unused fields, and join entities that are currently sat in different schemas. The first example of this approach was done in PR #531 .Whilst we transition from the models based directly on the tables to ones on our new views we'll have 2 of everything; 2
BillRunModel
,AddressModel
, etc. We didn't think this would be a problem but our initial attempts to create the new models have exposed an issue.Because we are not able to take advantage of ESM modules, when you specify a relationship between models you have to provide a path. Handily, Objection.js has a solution where you provide a base class and specify a
modelPaths
property.Because we put our legacy models in folders to help make it clear which schemas they came from, we needed to extend this further in the
LegacyBaseModel
.The issue is when Objection is trying to work out the relationships in a legacy model, it is seeing both models. This is causing relationships to break and unit tests to fail. Fortunately, the fix is simple. We just need to stop including the path to the new models in the
LegacyBaseModel
. Then, when Objection comes to deal with a relationship the only models it is seeing are the legacy ones. The same goes for the new models, because they only extendBaseModel
they only know of the ones in the root ofsrc/models
.