Feature: Built-in system for converting from query data #19
+108
−32
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.
Resolves #15
As noted in the Issue, models didn't have a first-class way of building from query data, which was a problem since relationships relied on this.
This PR introduces the ability to build from query data right into the
Model
class. For models that only have primitive properties, no extra work is needed. If the model has class properties, then the way to convert them is by overloading thecastValueForProperty
static method. It will probably look something like this:I decided to leave (although rename) the
ModelBuildsFromQueryData
interface. I'm really tempted to get rid of it. But I wanted to defer to @borkweb, who first added it, as to whether he thinks it's still necessary. I can't personally think of a use-case where we'd want to pass an interface whose only purpose is to be able to create models, when the underlying model is what's actually concretely passed. That sounds more like a factory.