IntentArchitect / Support

A repository dedicated to handling issues and support queries
3 stars 0 forks source link

OneToMany relationship naming of column #8

Closed leonAtRain closed 1 year ago

leonAtRain commented 1 year ago

Ask a question

When setting up two Models in the Domain diagram, I create a One to Many relationship from one table to the next - but the "Many" side gets a property which has the plural of the "One" which would never be possible - as it would always be "One"-id that is captured in that field. For example: Category -> SubCategory receives a "categoriesId" property, but in the SubCategory domain that would always be a specific "categoryId" How can this behavior be switched off or changed? I know there is in the DBMS settings a "plural/singular" setting for other similar conventions - but my setting is already set to Singular, and this has no affect here.

JonathanLydall commented 1 year ago

Hi @leonAtRain,

I've tried to reproduce this, but I don't think I've properly understood your reproduction steps, I've modelled the following which appears correct:

image

And the generation also seems correct to me for the following two classes:

@Entity
@Table(name = "categories")
@Data
@AllArgsConstructor
@NoArgsConstructor
@IntentManageClass(privateMethods = Mode.Ignore)
public class Category implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(columnDefinition = "uuid", name = "id", nullable = false)
    private UUID id;

    @NotNull
    @OneToMany(cascade = { CascadeType.ALL }, orphanRemoval = true, fetch = FetchType.LAZY)
    @JoinColumn(name = "category_id", nullable = false)
    private List<Subcategory> subcategories;

    public boolean isNew() {
        return this.id == null;
    }
}

and

@Entity
@Table(name = "subcategories")
@Data
@AllArgsConstructor
@NoArgsConstructor
@IntentManageClass(privateMethods = Mode.Ignore)
public class Subcategory implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(columnDefinition = "uuid", name = "id", nullable = false)
    private UUID id;

    @Column(columnDefinition = "uuid", name = "category_id", nullable = false, insertable = false, updatable = false)
    private UUID categoryId;

    public boolean isNew() {
        return this.id == null;
    }
}
leonAtRain commented 1 year ago

Turns out - there were a specific name captured into the Source End - Name of the relationship - which caused the "categoriesId" - after I changed it to "category" it then reflected correctly.