jmix-projects / jmix-old

DEPRECATED. Use https://github.com/jmix-framework/jmix
16 stars 3 forks source link

Consider renaming the related attribute of the ModelProperty annotation #569

Closed gorbunkov closed 4 years ago

gorbunkov commented 4 years ago

Suppose we have an entity:

@Table(name = "SAMPLE_ORDER")
@Entity(name = "sample_Order")
public class Order extends StandardEntity {
    private static final long serialVersionUID = -8651639140562527033L;

    @Column(name = "QUANTITY")
    private Integer quantity;

    @Column(name = "PRICE")
    private Integer price;

    //...

    @ModelProperty(related = {"quantity", "price"})
    public Integer getTotalAmount() {
        return (quantity != null && price != null) ?
                quantity * price :
                0;
    }
}

Properties quantity and price are related to the totalAmount. We have a method in MetadataTools to get related properties:

metadataTools.getRelatedProperties(Order.class, "totalAmount") //will return "quantity" and "price"

Things are getting worse when we need to find which fields depends on quantity. When the field with quantity property is modified on the screen we need to update the totalAmount value. In this case it is hard to name the relation between the quantity and the totalAmount.

Another argument for renaming is that "related" has too wide meaning. Maybe it can be changed to dependsOn:

    @ModelProperty(dependsOn = {"quantity", "price"})
    public Integer getTotalAmount() {
        return (quantity != null && price != null) ?
                quantity * price :
                0;
    }

Then methods for finding related properties may be as follows:

getDependsOnProperties("totalAmount") //returns "quantity" and "price"
getDependentProperties("quantity") //returns "totalAmount"
getDependentProperties("price") //returns "totalAmount"
knstvk commented 4 years ago

Will be implemented in haulmont/jmix-core#5