Skip to content

fix(cli): support keyTo option in belongsTo relation generator#11648

Open
Abubakar-K-Back wants to merge 2 commits into
loopbackio:masterfrom
Abubakar-K-Back:fix/belongs-to-keyto-support
Open

fix(cli): support keyTo option in belongsTo relation generator#11648
Abubakar-K-Back wants to merge 2 commits into
loopbackio:masterfrom
Abubakar-K-Back:fix/belongs-to-keyto-support

Conversation

@Abubakar-K-Back

Copy link
Copy Markdown

Description section:
Fixes #11647

When generating a belongsTo relation with a custom keyTo field, the CLI generator was silently ignoring the keyTo option it was not included in the generated @belongsTo decorator, and the FK type was always resolved from the destination model's primary key type instead of the actual keyTo field type.

Changes:

  • Pass keyTo to getBelongsTo() and include it in the decorator arguments
  • Resolve fktype from the actual keyTo field type using getModelPropertyType()
  • Pass keyTo into artifactInfo in generateControllers() for controller template access
  • Update controller EJS template to reflect the resolved keyTo field in the OpenAPI description

@Abubakar-K-Back Abubakar-K-Back force-pushed the fix/belongs-to-keyto-support branch from e0f623e to 5fc5eea Compare July 6, 2026 15:31
@aaqilniz

aaqilniz commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Hi, @Abubakar-K-Back. Can you please add the tests for your changes? And you need to fix the commit message.
loopback-next uses commitzen to generate commit messages.

The belongsTo relation generator ignores the keyTo option when provided.
This fix passes keyTo through to the model decorator, overrides fktype
using the target field's actual type, and reflects the keyTo in the
controller OpenAPI description.

Fixes loopbackio#11647

Signed-off-by: Abubakar Awan <abkawan6@gmail.com>
@Abubakar-K-Back Abubakar-K-Back force-pushed the fix/belongs-to-keyto-support branch from 5fc5eea to cb196ee Compare July 10, 2026 16:22
@Abubakar-K-Back Abubakar-K-Back changed the title add support for custom keyTo property in belongsTo relation generator… fix(cli): support keyTo option in belongsTo relation generator Jul 10, 2026
Adds integration tests verifying that the keyTo option is passed
through the --config flag and reflected in the generated model
decorator and controller description.

Also fixes the relation generator to propagate keyTo from CLI options
to artifactInfo so --config usage works correctly.

Signed-off-by: Abubakar Awan <abkawan6@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CLI generator ignores keyTo option when creating belongsTo relations

3 participants