-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Confusing @model() syntax #2142
Comments
@bajtos If its fine, I can try help with this feature implementation. Let me know if that's fine ? I have not worked with LB3, so I may need some guidance on exact requirements. |
@samarpanB of course it's fine to contribute! Sorry for the delay, I am often overwhelmed by GitHub notifications and I am still learning how to organize them so that I can focus on more important matters first. Shout out to https://octobox.io which helps me a lot!
Here is the code that's "normalizing" model configuration in LoopBack 3.x: // Settings
var excludedProperties = {
base: true,
'super': true,
relations: true,
acls: true,
dataSource: true,
};
if (typeof config.options === 'object' && config.options !== null) {
for (var p in config.options) {
if (!(p in excludedProperties)) {
settings[p] = config.options[p];
} else {
g.warn('Property `%s` cannot be reconfigured for `%s`',
p, modelName);
}
}
} else if (config.options != null) {
g.warn('The options property of `%s` configuration ' +
'must be an object', modelName);
} Essentially, we want to recognize few reserved top-level keys like |
Thanks for the update @bajtos . I am right now running little too busy with other projects. I'll start on it as soon as I get those completed. May be in 2-3 weeks. If anybody else is willing to pick this up from community, feel free to assign. |
No worries @samarpanB, take your time! On the second look, I think I posted a wrong LB3 code in my previous comment. Here is the correct one: function buildModelOptionsFromConfig(config) {
var options = extend({}, config.options);
for (var key in config) {
if (['name', 'properties', 'options'].indexOf(key) !== -1) {
// Skip items which have special meaning
continue;
}
if (options[key] !== undefined) {
// When both `config.key` and `config.options.key` are set,
// use the latter one
continue;
}
options[key] = config[key];
}
return options;
} |
@samarpanB if you are going to take sometime on this can I meanwhile take this up? |
Yes, please. Feel free to take it up @bhupesh-sf . @bajtos you can assign it to @bhupesh-sf if you see its fine. |
In LB3, users could specify model settings at two levels: as a root property or inside
options
property.See https://stackoverflow.com/q/53307168/69868 for an example of LB3 syntax applied in an LB4 project:
I am proposing to make two changes in LB4 to help users coming from LB3:
Recognize
options
the same way assettings
. In the example above,mongodb
settings are not picked by LB4 now. With the proposed change in place, LB4 will setcollection
toclients
as expected. Alternatively, tell the user settingoptions
that they are trying to set an unsupported model-definition property. This can be done at compiler level too.Allow settings to be provided as top-level properties, for example:
The text was updated successfully, but these errors were encountered: