-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
LoopBack models should inherit config.options from the parent #157
Comments
The requirement seems to boil down to dependencies between models and have a systematic way to resolve/inject the dependencies. |
Any updates on this? Is the manual way still the best way? |
@glesage No updates so far. |
This is no longer relevant, LoopBack 2.0 decoupled datasources config from model definition.
This is still relevant. The implementation would most likely break backwards compatibility. Related issue: #397 A better way for customizing built-in models and models from components |
Let's bring this issue back to life. For the upcoming 3.0 release, I am proposing to modify juggler's model builder to inherit model settings when subclassing a new model. app.model('MyUser', {
options: { base: 'User' },
dataSource: 'db'
});
// expected outcome:
assert(MyUser.settings.__proto__ === User.settings); |
I think that would be great! Options is the inheritance of the setting? |
/cc @davidcheung |
Loosely related #1485 |
ACLs are not inherited either, see #2270. As for inheriting relations, pure prototypal inheritance may not be enough. Consider this scenario: We have a parent model accessTokens: {
model: 'AccessToken',
type: 'hasMany',
// this is omitted: foreignKey: 'userId'
} When attached to a datasource, Now when we create A possible solution is to always fill in |
We agreed this required a bit of research to find out what and how should be inherited when subclassing a model. We don't have bandwidth to address it in 3.0 time. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the |
When LB developer wants to access built-in LB models via app.models, he has to define subclasses in models.json. The current implementation requires that a lot of config options of the base model must be repeated in the subclass definition.
This has several disadvantages:
Below are the use cases I discovered while writing E2E tests for loopback-angular.
datasource
Result:
Since the new model is a subclass of a built-in model, it should use the same datasource that was configured for the User model.
If the datasource of the base class was not resolved yet, but it has
autoAttach
property, then the process of attaching the subclass to a datasource should be deferred toloopback.autoAttach
.relations
Result:
To fix this problem, one has to re-define User relations:
The text was updated successfully, but these errors were encountered: