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

fix(sequelize): extend Inclusion interface with "required" property #10192

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions extensions/sequelize/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

declare module '@loopback/repository' {
interface Inclusion {
/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does it need to affect the types of core repository module, instead of type extension in the Sequelize repository itself. For the respective methods (find(), findOne(), and findById()).

I'm not certain about the behaviour this code will have but It can reflect to non sequelize repositories as well, which might not be intended here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shubhamp-sf Thanks for reviewing this. Yes, the TS declaration merging approach affects non-sequelize repositories too. Extending the method interfaces is much better, however, it doesn't cover the relation query "find" case like:

myRepository(foreignKey).find({
  include: [
    {
      // ...
      required: true
    }
  ]
}

I tried a couple of approaches for that case. Perhaps defining new interfaces like "SequelizeHasManyRepositoryFactory" that extend the find method in the underlying interfaces such as HasManyRepository?

* Setting this option to true will result in an inner join query that
* explicitly requires the specified condition for the child model.
*
* @see https://loopback.io/pages/en/lb4/readmes/loopback-next/extensions/sequelize/#inner-join
*/
required?: boolean;
}
}

/**
* Interface defining the component's options object
*/
Expand Down