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

loopback 4: The "find", "delete" and "patch" methods do not work in a relation #2123

Closed
ghost opened this issue Nov 30, 2018 · 4 comments
Closed
Assignees
Labels
Relations Model relations (has many, etc.) stale

Comments

@ghost
Copy link

ghost commented Nov 30, 2018

Description

loopback 4: The GET, DELETE and PATCH methods do not work in a relation when todoListId is dynamically generated as a text string.

It works normally.

  @belongsTo(() => TodoList)
  todoListId: number;

it does not work, only the post method

  @belongsTo(() => TodoList)
  todoListId: string;

Link to github: example todo-list

todo-list

initially I tried to do the relations with the documentation, with the fields of ids of type string, and it did not work, only the method post. after trying in various ways and without getting any results, download the example of todo-list, and it worked normally, and when only I change the data type of todoListId, it does not work !, it's as if I omitted the ids in the queries , why also I try with:

@get ('/ companies', {
    responses: {
      '200': {
        description: 'Array of Company model instances',
        content: {
          'application / json': {
            schema: {type: 'array'},
          },
        },
      },
    },
  })
  async find (
    @ param.query.object ('filter', getFilterSchemaFor (Company)) filter ?: Filter,
  ): Promise <Company []> {
    console.log (filter);

    const result: any = await this.companyRepository.find ();
    for (const key in result) {
      result [key] .currencies = await this.currencyRepository.find ({
        where: {companyId: result [key] .id},
      });
      console.log ('result >>>>>', result [key] .id.valueOf ());
    }
    return result;
  }

and even without getting any results with the string type

Does anyone know what's going on? Please help me!

@ghost
Copy link
Author

ghost commented Nov 30, 2018

I was doing more tests and I found that the problem is not the data type of the id field, the problem is the number of digits, when todolistId is 24 digits (number of digits of an ObjetcId), it is when the methods do not work mentioned above. Why does that happen? Is there any restriction?

 _id:ObjectId("a47d0976b8636ad32bce0cc2")

@dhmlau dhmlau transferred this issue from strongloop/loopback Dec 5, 2018
@dhmlau dhmlau added the Relations Model relations (has many, etc.) label Dec 5, 2018
@b-admike
Copy link
Contributor

b-admike commented Dec 5, 2018

Hi @germancv Thank you for the detailed steps. I think this is similar to #2085 and #1987. Do you mind looking at #2085 and if your issue is a duplicate, then let's continue discussion there and use it for tracking.

I was doing more tests and I found that the problem is not the data type of the id field, the problem is the number of digits, when todolistId is 24 digits (number of digits of an ObjetcId), it is when the methods do not work mentioned above. Why does that happen? Is there any restriction?

There's a lot of history behind this which I tried to look up, but here is what the docs currently say https://github.com/strongloop/loopback-connector-mongodb#strictobjectidcoercion-flag. I think as part of #2085 we'll have to improve the strictObjectIDCoercion flag or find a proper alternative solution.

@stale
Copy link

stale bot commented Jan 24, 2020

This issue has been marked stale because it has not seen activity within six months. 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. This issue will be closed within 30 days of being stale.

@stale stale bot added the stale label Jan 24, 2020
@stale
Copy link

stale bot commented Feb 23, 2020

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.

@stale stale bot closed this as completed Feb 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Relations Model relations (has many, etc.) stale
Projects
None yet
Development

No branches or pull requests

2 participants