Open creynders opened 7 years ago
Another solution, probably even easier:
schema.paths
property to export a schema in memoryI'm trying to find another solution instead keystone now because it's force me to rewrite 2 models (keystone and mongoose) in migrations. It's difficult to test keystone models at now, but if @creynders will add possibility to import existing model in app it would more flexible and would be the best admin UI for me.
@VadimShvetsov importing existing models won't be for the near future. The problem is that Keystone expands the functionality and data types. E.g. an e-mail field will be a simple String in mongoose, but will be of type Email in Keystone, so you need some way to tell keystone that the simple string declaration in the mongoose model should be treated as Email in keystone. I.e it will require some kind of inheritance scheme where you can say that a keystone model should use a mongoose schema as a base, but allows you redefining/detailing the fields.
@creynders Yeah, I understand, but for me it's more convenient to not expand my model with Keystone types, I need to tweak paths like 'email' with validators and my own methods easily, it's quite difficult with defined types. Adding existing models can add more flexibility to the framework but it's too much refactoring needed for it and I understand it's not necessary now.
description
I really need some way to export the mongoose schemas as generated by the fields in Keystone. This is useful for a few reasons:
proposed solutions
schema.add
allowing to export whatever comes in as json for instanceschema.add
directly, but a proxy instead, which would allow registering handlers toadd
methodFor the moment I'll be monkey patching in my own projects, since time is of issue. But I'm wondering what solution you guys would prefer?
@JedWatson @mxstbr