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.
To fix #310 I needed a way to reliably pass a model property definition to a DML drivers
valueToProperty
method from within anInstance
.Since some properties were set on
Model.properties
whilst others like ids & association fields existed only in an array of strings (and their types were inferred by the drivers DDLsync
code) this made life difficult.It also introduced duplicate code, and issues with redefining key columns, and no good way to specify exact types for ALL columns.
I've come up with
Model.allProperties
which stores definitions of all constant properties (normal properties, id props, association fields). Extra properties remain separate as they are transient.This allowed for some nice code cleanups in driver
sync
methods, and a simplification ofopts.data
initialization code insideInstance
.It also fixes some inconsistent behaviour I found along the way, like
Model.create
casting properties when they are set andinstance.save
not doing so.Lastly, it introduces a new syntax (only internally for now) for defining keys, as discussed in #313 :
Composite keys:
Keys are currently still set via the
id
property, however now that the underlying work is done, we can change this in future to thekey
syntax without too much pain.Note: We now have both
Model.allProperties
andModel.properties
. It should be possible to remove the latter in the future. It was taking me forever to finish this refactor, so consider this code a transition step.@dresende the failing tests depend on sql-query 0.11.12 being published - the change in sql-query is small.