Use mixins in schema declarations
See original GitHub issueHello. Is there any way to use mixins with umongo Document class? I have following structures:
class A(EmbeddedDocument):
field1 = StringField()
field2 = StringField()
...
field99 = StringField()
class B(Document):
field1 = StringField()
field2 = StringField()
...
field99 = StringField()
items = ListField(EmbeddedDocumentField(A))
I want to put all of my fields to another class and use it as mixin for A and B. Is it possible in umongo?
Issue Analytics
- State:
- Created 4 years ago
- Comments:5
Top Results From Across the Web
complexType "mixin" | XML Schema Documentation
The fully qualified classname of the mixin class that defines the annotations to overlay on the object. This must be an abstract class...
Read more >Mixin and Custom Base Classes
In addition to using a pure mixin, most of the techniques in this section ... The most basic way to specify a column...
Read more >Client schema | Creatio Academy
When naming mixins, use an -able suffix in the schema name. For example, name a mixin that enables serializing in the components Serializable...
Read more >Is there a way to define certain parts of my JSON schema as ...
One way you can extend the core schema is to use allOf to essentially mixin the core schema with your new fields. {...
Read more >Mixins API Endpoint | Adobe Experience Platform
The /mixins endpoint in the Schema Registry API allows you to programmatically manage XDM mixins within your experience application.
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 FreeTop 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
Top GitHub Comments
@gerasim13 #267 should fix this.
There’an an issue with your implementation: the mixin overrides the doc class fields in case of name collision, while expected behaviour would be the doc class overriding the mixin. This is why I use
setdefault
in #267.Right. I just fell into this myself.
I think this could be fixed by modifying
_collect_schema_attrs
in builder.py. Make it recursive, and change parameter totemplate
instead oftemplate.__dict__
.I don’t have time for this right now but I’d be happy to merge a PR implementing it.