-
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
MySQL: can't GET relations in response after first npm start
#3356
Comments
npm start
npm start
@nabdelgadir, could you please take a look? Thanks. |
More information about this: I also tried running |
Thanks for reporting this issue. We couldn't reproduce it on our end. For us, the |
@nabdelgadir That's exactly the bug that I found! |
@gonzarascon Thank you! And that's very strange. Using the explorer, it showed us the schema with the user object but it just returned the |
Hey @nabdelgadir ! I started to work on the repository for reproducing this bug using the todo-list example and guess what? After running I'm suspecting it could be a problem with the I'll try riding off all cached data on my PC in case there's a problem with that. |
@gonzarascon I see where the confusion is coming from. So specifically for the However, in your case, we still don't support inclusion of related models so you won't see the But, if you need inclusion now, you can hardcode it similar to how we did it in our Let me know if you have any other questions. 😄 |
@nabdelgadir oh, I see... But, when I ran the |
@gonzarascon Did you remember to use the filter when doing your @bajtos @strongloop/sq-lb-apex |
@nabdelgadir Do you have any example on how to implement |
@gonzarascon async find(
filter?: Filter<Todo>,
options?: Options,
): Promise<TodoWithRelations[]> {
// Prevent juggler for applying "include" filter
// Juggler is not aware of LB4 relations
const include = filter && filter.include;
filter = {...filter, include: undefined};
const result = await super.find(filter, options);
// poor-mans inclusion resolver, this should be handled by DefaultCrudRepo
// and use `inq` operator to fetch related todo-lists in fewer DB queries
// this is a temporary implementation, please see
// https://github.com/strongloop/loopback-next/issues/3195
if (include && include.length && include[0].relation === 'todoList') {
await Promise.all(
result.map(async r => {
// eslint-disable-next-line require-atomic-updates
r.todoList = await this.todoList(r.id);
}),
);
}
return result;
} You can simplify it to the following so you don't need the filter and it includes them by default: async find(
filter?: Filter<Todo>,
options?: Options,
): Promise<TodoWithRelations[]> {
// Prevent juggler for applying "include" filter
// Juggler is not aware of LB4 relations
filter = {...filter, include: undefined};
const result = await super.find(filter, options);
// poor-mans inclusion resolver, this should be handled by DefaultCrudRepo
// and use `inq` operator to fetch related todo-lists in fewer DB queries
// this is a temporary implementation, please see
// https://github.com/strongloop/loopback-next/issues/3195
await Promise.all(
result.map(async r => {
// eslint-disable-next-line require-atomic-updates
r.todoList = await this.todoList(r.id);
}),
);
return result;
} Let me know if this helps. 😄 |
@nabdelgadir thank you very much! So far, I tried all three options: including the filter in the url, modifying the So, if I had a filter as the In conclussion to this brief explanation, I'll stick to the URL method for now and I hope the relations feature to be supported soon! Thank you @nabdelgadir for all your help! |
@gonzarascon Thank you for the explanation! I'm going to close this issue, but if you have any further questions, feel free to ask. 😄 |
Hello!
I just finished the Todo-List Tutorial from the documentation and implemented the Model/Repository relation as the tutorial shows, the only diference between it and my project it's that I have been using a local MySQL server from the beginning, so I created my Models based on the MySQL tables.
In my project I have the next relation =>
A User can have many Courses
.At the first start of the app, when I requested
/courses
withGET
, the endpoint responded correctly with an array of objects (Courses) and inside of each object, another object with the user that created that Course. That was fine because I wanted so to happen.Now, from the second time I did
npm start
(With no changes either on the Models or Repositories), when I request/courses
withGET
, the endpoint only respond with an array of Courses with no data about Users.This is an strange bug because the endpoint's Example Value and Schema shows the correct structure:
I looked for similar situations, but I could not find any!
The text was updated successfully, but these errors were encountered: