-
Notifications
You must be signed in to change notification settings - Fork 8
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 crud-generator position group for ref-fields #2613
base: main
Are you sure you want to change the base?
Conversation
1240f92
to
cb9b121
Compare
.map( | ||
(prop) => | ||
`${prop.name}${prop.nullable ? `?` : ``}: ${ | ||
[ReferenceType.EMBEDDED, ReferenceType.SCALAR].includes(prop.reference) ? prop.type : "string" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@johnnyomair @nsams I think we don't want to support OneToMany
and ManyToMany
fields in groupByFields
. Should I throw an error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add an example for this? Maybe a unit test?
@johnnyomair I added an example in demo. I also found another bug when a dedicatedResolverArg is used for position-group (which are probably one of the most used fields) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a changeset for this fix.
@InjectRepository(ProductVariant) private readonly repository: EntityRepository<ProductVariant>, | ||
) {} | ||
|
||
async incrementPositions(group: { product: string }, lowestPosition: number, highestPosition?: number) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be better if the product entity was passed here, and not the ID?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this would be much more complicated. in this case grouping is done by references to other entities. they can be configured differently. most of the time it will probably be something like this:
@ManyToOne(() => MyEntity, { ref: true })
myReferencedEntity?: Ref<MyEntity>;
but it could also be a eager reference. They require different code. id is always present.
CRUD-Generator position-feature generates wrong code if groupByFields contains Ref field.
Ref field requires to generate
baseEntity.refEntity.id
(orbaseEntity.refEntity?.id
if optional) to call position-functions from service, but was alwaysbaseEntity.refEntity
.Type needs to be string for Ref and prop.type for Scalars and Embedded. OneToMany and ManyToMany shouldn't be possible at all.