Skip to content

fix: fix generation of DAO objects with cycles #1279

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lloyd-juicelabs
Copy link

@lloyd-juicelabs lloyd-juicelabs commented Mar 25, 2025

  • Do only one thing
  • Non breaking API changes
  • Tested

What did this pull request do?

When generating models that are recursive, the current pullRelationships method will incorrectly provide an empty result if the type is already in the cache.

This change alters the generator so it walks the tree twice, once to locate all the types and then a second time to actually generate all the code once the cache is correctly populated with all the types.

I have provided a test case ensure generation is working correctly.

fix #1242

User Case Description

Full bug description here: #1242

@lloyd-juicelabs lloyd-juicelabs force-pushed the fix-dao-generation-with-cycles branch from 85b4d14 to 35b36f5 Compare March 25, 2025 01:40
@tr1v3r tr1v3r changed the title Fix generation of DAO objects with cycles fix: fix generation of DAO objects with cycles Mar 25, 2025
@lloyd-juicelabs lloyd-juicelabs force-pushed the fix-dao-generation-with-cycles branch from 35b36f5 to 1b23dc0 Compare April 16, 2025 02:10
for i, relationship := range relationships {
varType := strings.TrimLeft(relationship.Field.FieldType.String(), "[]*")
cached := cache[varType]
result[i] = *field.NewRelationWithType(field.RelationshipType(relationship.Type), relationship.Name, varType, cached...)
Copy link
Member

Choose a reason for hiding this comment

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

why rebuild a new relation type here?

Copy link
Author

Choose a reason for hiding this comment

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

As far as I can tell this is needed as the cache just has the childRelations? I thought this is what the old code was doing, but the childRelations were just missing.

You have a better idea of how this should work though, so feel free to suggest something better or change my branch, my understanding is very surface level.

Copy link
Member

Choose a reason for hiding this comment

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

Why does the implementation use a separate loop for assigning values to result[i] instead of performing the assignment within the initial loop, as seen in the original implementation? What are the technical considerations behind this design choice?

@tr1v3r
Copy link
Member

tr1v3r commented Apr 28, 2025

Duplicate of #1270

@tr1v3r tr1v3r marked this as a duplicate of #1270 Apr 28, 2025
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.

Generation of models with recursive associations fail
2 participants