Closed luasenvy closed 5 years ago
This is very strange example. I don't recommend to use mixing schemas ... you can use chaining for schema operation like this:
ROUTE('GET /api/example *Example --> @get @query @get-other-type (response)');
So the answer:
Your example won't work. You need to know that Schema operation like setGet()
, setQuery()
, addWorkflow()
works only with schema instance. What is the schema instance? It's an object generating according to the schema, this type of object contains a meta data about the schema.
var model = $CREATE('Example');
// Now model is SchemaIntance
model.$get(...)
model.$save(...)
model.$insert(...)
model.$update(...)
model.$workflow('....');
Back to your example:
schema.setGet(async function($){
var model = $.model;
// model is Schema Instance
// So you can perform:
// model.$workflow('..')
// model.$save();
// model.$query()
// But now you want to rewrite "model" with a new object
// So another operation won't know about the schema because you rewrite it
$.callback({ body: '<div></div>' });
// Possible solution:
model.data = { body: '<div></div>' };
$.callback(model);
});
thank you for reply.
I just wanted to reuse it without separating it into a function like the DAO
in the MVC framework.
my curiosity was resolved. so close it :)
can i reuse schema workflow?
for example
schema/Example:
controller/example.js