Better support for nested models and collections
See original GitHub issueAt the moment the support for nested structures is limited. We’d like to improve this as it’s a common situation and should in theory work as you would expect. This issue is a place to collect all the things we’d like to achieve when we get to improving this support.
- Errors should be set on the child, not with dot notation on the parent. (or both?)
- Determine the difference between
parent.saved('child.attr')
andparent.child.saved('attr')
- Provide a nice mechanism to convert nested objects to models
Issue Analytics
- State:
- Created 6 years ago
- Reactions:11
- Comments:14
Top Results From Across the Web
Nested BackboneJS Models - Andrew Goldis - Medium
The Views (and Collection / Layout views) are designed to work with simple, flat models. Having a unified but complicated nested model and...
Read more >MongoDB schema design - multiple collections vs nested ...
In your example it probably makes more sense to create two separate collections. Embedding documents is very useful in some cases, ...
Read more >Body - Nested Models - FastAPI
Editor support (completion, etc), even for nested models; Data conversion ... You can use more complex singular types that inherit from str ....
Read more >Collection-oriented workflows represent nested data ...
... addition, input data outside of an actor's scope is automatically forwarded downstream. where collection-aware actors can concurrently process collections ...
Read more >create contextapp with single model and nested collection
Not currently no. Pretty much everything in Konstrukt is based around the collections so it's more about managing groups of data than individual ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I extended
Model
like this for a simple relation:The
init()
is just there so you can more easily add things to the constructor. All I really need to do is addthis._relations = {};
.Then, in the model for a particular resource, I can just do this:
Nothing crazy, just a simple way to do it. The relation is cached, and there’s nothing invalidating that cache on update, but other than that it’s works well.
@MichMich There are two stages here: 1) plan it, 2) implement it. I’m not confident that we know what the solution is yet, so while the implementation might be quick, it’s difficult to estimate how long it would take to come up with a solution.
Can you give me an example of one of your model schema’s?
The API for this should be as simple as:
I think if we can come up with an API that is “acceptable”, we’re good to go. This would only solve 1 of the 3 points laid out in the opening statement. I don’t believe the other two are difficult to solve though:
Should be set on the child, such that
parent.errors
is empty butparent.child.errors
is populated.These should both be supported because they are not equivalent. This first uses the saved child’s property, and the second uses the active child’s saved property. This is a bit confusing but it will be very difficult to avoid that, unless we disallow nesting that isn’t delegated (I don’t want to do this though because it could force a lot of boilerplate).