strongloop / loopback

LoopBack makes it easy to build modern applications that require complex integrations.
http://loopback.io
Other
13.23k stars 1.2k forks source link

Getting "Invalid target model for scope" in hasMany relationships with model.attachTo(dataSource) #3885

Closed JuergenSimon closed 5 years ago

JuergenSimon commented 6 years ago

Description/Steps to reproduce

Expected result

Additional information

node -e 'console.log(process.platform, process.arch, process.versions.node)': darwin x64 10.1.0

npm ls --prod --depth 0 | grep loopback: │ ├── loopback@3.19.0 │ ├── loopback-connector-postgresql@3.3.1 ├── loopback@3.18.2 ├── loopback-boot@2.27.0 ├── loopback-component-explorer@5.2.0 ├── loopback-component-oauth2@3.1.0 ├── loopback-connector-postgresql@3.3.0 ├── loopback-ds-timestamp-mixin@3.4.1 ├── loopback-storage-service@1.0.4 npm ERR! missing: foobar-backend-common@git+https://8420f39f99501d01466e4698e9e1e04ccac448e8:x-oauth-basic@github.com/FOO/foobar-backend-common.git, required by foobar-backend@1.0.0-SNAPSHOTS npm ERR! missing: loopback@3.19.0, required by foobar-backend-common@git+https://8420f39f99501d01466e4698e9e1e04ccac448e8:x-oauth-basic@github.com/FOO/foobar-backend-common.git#abcb29d64c5fc53ff457c73bb990cd578f8c6041 npm ERR! missing: loopback-connector-postgresql@3.3.1, required by foobar-backend-common@git+https://8420f39f99501d01466e4698e9e1e04ccac448e8:x-oauth-basic@github.com/FOO/foobar-backend-common.git#abcb29d64c5fc53ff457c73bb990cd578f8c6041 npm ERR! missing: moment@2.22.1, required by foobar-backend-common@git+https://8420f39f99501d01466e4698e9e1e04ccac448e8:x-oauth-basic@github.com/FOO/foobar-backend-common.git#abcb29d64c5fc53ff457c73bb990cd578f8c6041 npm ERR! missing: moment-timezone@0.5.17, required by foobar-backend-common@git+https://8420f39f99501d01466e4698e9e1e04ccac448e8:x-oauth-basic@github.com/FOO/foobar-backend-common.git#abcb29d64c5fc53ff457c73bb990cd578f8c6041 npm ERR! missing: supertest@3.1.0, required by foobar-backend-common@git+https://8420f39f99501d01466e4698e9e1e04ccac448e8:x-oauth-basic@github.com/FOO/foobar-backend-common.git#abcb29d64c5fc53ff457c73bb990cd578f8c6041 npm ERR! missing: winston@2.4.2, required by foobar-backend-common@git+https://8420f39f99501d01466e4698e9e1e04ccac448e8:x-oauth-basic@github.com/FOO/foobar-backend-common.git#abcb29d64c5fc53ff457c73bb990cd578f8c6041 npm ERR! missing: loopback-datasource-juggler@3.20.2, required by loopback@3.19.0 npm ERR! missing: debug@2.6.9, required by loopback@3.19.0 npm ERR! missing: strong-remoting@3.11.0, required by loopback@3.19.0 npm ERR! missing: jayson@2.0.6, required by strong-remoting@3.11.0 npm ERR! missing: debug@2.6.9, required by strong-remoting@3.11.0 npm ERR! missing: JSONStream@1.3.2, required by jayson@2.0.6 npm ERR! missing: commander@2.15.1, required by jayson@2.0.6 npm ERR! missing: jsonparse@1.3.1, required by JSONStream@1.3.2 npm ERR! missing: async@0.9.2, required by loopback-connector-postgresql@3.3.1 npm ERR! missing: moment@2.22.1, required by moment-timezone@0.5.17 npm ERR! missing: async@1.0.0, required by winston@2.4.2

dhmlau commented 6 years ago

@jannyHou , could you please help? thanks.

jannyHou commented 6 years ago

@JuergenSimon @dhmlau I don't think we support a dynamic database switch after the relation is established, it's restricted by design in loopback 3.

A workaround could be after switching the datasource, call ModelA.hasMany(ModelB, settings) again to re-establish the relation, @JuergenSimon you can try if that works.

I loopback 4 we have an opportunity to support this feature.

stale[bot] commented 5 years ago

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.

stale[bot] commented 5 years ago

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 CODEOWNERS file at the top-level of this repository.