jaxio / celerio-angular-quickstart

Generate an Angular 5 CRUD application from an existing database schema (we provide a sample one)
Apache License 2.0
479 stars 138 forks source link

repeated imports in entity-detail.component.ts.e.vm #10

Closed vivienmast closed 7 years ago

vivienmast commented 7 years ago

In entity-detail.component.ts.e.vm, lines 8-12: #foreach ($relation in $entity.xToOne.list) #if(!$relation.to.type.equals($entity.model.type)) import {${relation.to.type}} from '../$relation.toEntity.model.var/${relation.toEntity.model.var}'; #end #end

when creating an Entity with several X-to-One relations with the same target type (e.g., a PROJECT entity with a project manager and a deputy project manager which are both of Type USER), the component gets imported repeatedly, leading to a compile error.

I assume the same happens for Many-To-Many Relations (lines 13-16) though I didn't test that.

EDIT: Changing lines 8-12 to the following solved this for me (solution for lines 13-16 is probably analogous):

#set($imports = []) #foreach ($relation in $entity.xToOne.list) #if(!$relation.to.type.equals($entity.model.type) && !$imports.contains($relation.to.type)) import {${relation.to.type}} from '../$relation.toEntity.model.var/${relation.toEntity.model.var}'; #set($temp = $imports.add($relation.to.type)) #end #end

vivienmast commented 7 years ago

A similar issue occurs for entity-list.component.ts.e.vm, and entity.ts.e.vm

nromanetti commented 7 years ago

thanks, good catch. Why setting to $temp ?

set($temp = $imports.add($relation.to.type))

nromanetti commented 7 years ago

fixed, thanks!

vivienmast commented 7 years ago

Setting temp is just a hack to prevent Velocity from printing the return value of the add() method to the file. Not sure if there is a better way to do this, but it works... It might be better to give a variable name that makes this explicit such as $swallowReturnValue to make the code more readable.