Skip to content
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

migrateSchema will not work if there is blongTo relationship #3263

Closed
m98 opened this issue Jun 27, 2019 · 2 comments
Closed

migrateSchema will not work if there is blongTo relationship #3263

m98 opened this issue Jun 27, 2019 · 2 comments
Assignees
Labels

Comments

@m98
Copy link

m98 commented Jun 27, 2019

Steps to reproduce

I'm new to LoopBack4, and I was following the tutorials to generate a simple blog API using LoopBack, and I knew I can use 'migrateSchema' to create database tables using my models.

Just follow the tutorial to generate the simple order, customer model and relationships, and try to run the app after adding the relationship (this link)

Current Behavior

When I use npm strat I get this error:

Cannot start the application. TypeError: Cannot read property 'target' of undefined
    at resolveBelongsToMetadata (E:\personal\project\node_modules\@loopback\repository\dist\relations\belongs-to\belongs-to-accessor.js:37:54)
    at Object.createBelongsToAccessor (E:\personal\project\node_modules\@loopback\repository\dist\relations\belongs-to\belongs-to-accessor.js:16:18)
    at StoryRepository.createBelongsToAccessorFor (E:\personal\project\node_modules\@loopback\repository\dist\repositories\legacy-juggler-bridge.js:184:28)
    at new StoryRepository (E:\personal\project\node_modules\dist\repositories\story.repository.js:22:26)

Link to reproduction sanbox

https://github.com/m98/loopback4-example/tree/master/src

Additional information

Windows 10 'win32', 'x64', '10.16.0'

@m98 m98 added the bug label Jun 27, 2019
@dhmlau
Copy link
Member

dhmlau commented Jun 27, 2019

In order to do that, we'll need strong relation with referential integrity which is captured in #2331.

As a workaround, this documentation page (https://loopback.io/doc/en/lb4/todo-list-tutorial-sqldb.html) showed how to modify the @model decorator to contain the foreign key information when running migrateSchema.

Hope it helps.

@dhmlau dhmlau self-assigned this Jun 27, 2019
@m98
Copy link
Author

m98 commented Jun 28, 2019

Actually, I'm disappointed by loopback documentation, and also errors which are not meaningful, especially when you search them on Google, and you can't find anything meaningful by the loopback error message.

@m98 m98 closed this as completed Jun 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants