You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Related model shared = false vs. REST exposure #346
It seems that Model.setup doesn't take into account when a model is not shared - the REST API endpoints are created regardless. Also, setting the generated relation method to shared = false has no effect (this is the method outlined in the docs):
Do you expect Model.setup() to skip the steps for remoting if shared is false? A typical flow is to configure the model first before calling app.model(MyModel). I would argue it's fine to build the remoting metadata/methods regardless.
For 'Project.prototype['__create__history'].shared = false;', do you see the endpoint in the API explorer? Can you still invoke it? I wonder if you set the flag too late before REST routes are built? I think we should have a method to remove it from remoting after the fact.
Hi @raymondfeng - it might be the case that I'm setting the flag too late. Being able to selectively remove methods from REST exposure would certainly be helpful.
How would you recommend 'registering' models, so they're available from app.loopback.getModel(), yet are not exposed? I find myself using getModel in a few places, even for 'embedded' models, and I like being able to have a unified way to reach them vs. using app.models[modelName] directly.
How would you recommend 'registering' models, so they're available from app.loopback.getModel(), yet are not exposed? I find myself using getModel in a few places, even for 'embedded' models, and I like being able to have a unified way to reach them vs. using app.models[modelName] directly.
Both app.loopback.getModel(name) and app.models[name] are valid way of accessing the model. The first one is relying on a global static registry, which is something we would like to remove in favour of app.models[name] in the future.
Whenever you call loopback.createModel or Model.extend, the model is registered in the global static registry and is available via loopback.getModel(name). Which means you don't have to register your models if you are accessing them via loopback.getModel.
The method app.model(model) has two purposes:
modify the configuration of an existing model - attach to a datasource, add relations, etc.
register the model in app.models
Here is my question: How do you setup your application models? Do you use loopback-boot or do you have your own bootstrapper?
@bajtos thanks for the clarification, that makes sense. I am still on the deprecated loopback-boot setup (the one where app is passed in to the model's module), but I'm hoping to switch over my code-base soon. I prefer to declare 'embedded' models in code only, using a memory datasource (as a convenience, items are never stored there).
It would be nice to have 'one-off' models from time to time, not actually registered anywhere. Is that possible?
How would you recommend 'registering' models, so they're available from app.loopback.getModel(), yet are not exposed? I find myself using getModel in a few places, even for 'embedded' models, and I like being able to have a unified way to reach them vs. using app.models[modelName] directly.
One can set shared: false in server/model-config.json to have the model available via app.models.MyModel and app.registry.getModel('MyModel') without exposing the model via the REST API.
Here is an example of creating such model programatically:
varMyModel=app.registry.createModel({/* model definition */});app.model(MyModel,{public: false});
Being able to selectively remove methods from REST exposure would certainly be helpful.
You can use disableRemoteMethod for that, see the docs.
Activity
raymondfeng commentedon Jul 7, 2014
Do you expect Model.setup() to skip the steps for remoting if shared is false? A typical flow is to configure the model first before calling app.model(MyModel). I would argue it's fine to build the remoting metadata/methods regardless.
For 'Project.prototype['__create__history'].shared = false;', do you see the endpoint in the API explorer? Can you still invoke it? I wonder if you set the flag too late before REST routes are built? I think we should have a method to remove it from remoting after the fact.
fabien commentedon Jul 7, 2014
Hi @raymondfeng - it might be the case that I'm setting the flag too late. Being able to selectively remove methods from REST exposure would certainly be helpful.
How would you recommend 'registering' models, so they're available from
app.loopback.getModel(), yet are not exposed? I find myself using getModel in a few places, even for 'embedded' models, and I like being able to have a unified way to reach them vs. usingapp.models[modelName]directly.bajtos commentedon Jul 8, 2014
Both
app.loopback.getModel(name)andapp.models[name]are valid way of accessing the model. The first one is relying on a global static registry, which is something we would like to remove in favour ofapp.models[name]in the future.Whenever you call
loopback.createModelorModel.extend, the model is registered in the global static registry and is available vialoopback.getModel(name). Which means you don't have to register your models if you are accessing them vialoopback.getModel.The method
app.model(model)has two purposes:app.modelsHere is my question: How do you setup your application models? Do you use loopback-boot or do you have your own bootstrapper?
fabien commentedon Jul 8, 2014
@bajtos thanks for the clarification, that makes sense. I am still on the deprecated loopback-boot setup (the one where
appis passed in to the model's module), but I'm hoping to switch over my code-base soon. I prefer to declare 'embedded' models in code only, using a memory datasource (as a convenience, items are never stored there).It would be nice to have 'one-off' models from time to time, not actually registered anywhere. Is that possible?
bajtos commentedon Jul 8, 2014
Thanks for the explanation.
Not at the moment.
raymondfeng commentedon Jul 23, 2014
You can have the one-off models if you use juggler apis, for example:
bajtos commentedon Apr 7, 2016
One can set
shared: falseinserver/model-config.jsonto have the model available viaapp.models.MyModelandapp.registry.getModel('MyModel')without exposing the model via the REST API.Here is an example of creating such model programatically:
You can use
disableRemoteMethodfor that, see the docs.Example:
@fabien I hope that I have answered your questions, I am closing this issue. Please open a new issue if you have any more questions.