
Multiple distinct belongs to relationships between same models
Hi,
I have a table containing relations. In this model two types of relations are present. Supplier and Customer.
I have also a separate model to save information about the link between these two relations type to each other. Let's call this model SupplierCustomer.
A SupplierCustomer record belongs to both a Relation of type Supplier and a Relation of type Customer. To configure this I created two belongs to relations from SupplierCustomer to Relation model.
- SupplierCustomer Belongs to Relation with name: supplier_relation (inverse relation = has many customers)
- SupplierCustomer Belongs to Relation with name: customer_relation (inverse relation = has many suppliers)
But this is not working. For some reason Betty Blocks is seeing these relation ships as one of the same, so in the SupplierCustomer model, the value in supplier_relation property will be also added to the customer_relation property of this model.
Main question: Why does Betty Blocks give me this behaviour although te relations are unique by naming.
Secondary question:
I think this can be solved in two ways:
- Use a has and belongs to many relationship on the Relation model itself. But in this case I can't save additional detail about each link between the supplier-relation and customer-relation. For example "preferred supplier".
- Split the relation model into two separate models. One for Suppliers and one for customers and use the link model SupplierCustomer between these models. But that require an additional model (and block) that has exact the same properties.
So Is there a more efficient way that will work in Betty Blocks?
Hi,
I have a table containing relations. In this model two types of relations are present. Supplier and Customer.
I have also a separate model to save information about the link between these two relations type to each other. Let's call this model SupplierCustomer.
A SupplierCustomer record belongs to both a Relation of type Supplier and a Relation of type Customer. To configure this I created two belongs to relations from SupplierCustomer to Relation model.
- SupplierCustomer Belongs to Relation with name: supplier_relation (inverse relation = has many customers)
- SupplierCustomer Belongs to Relation with name: customer_relation (inverse relation = has many suppliers)
But this is not working. For some reason Betty Blocks is seeing these relation ships as one of the same, so in the SupplierCustomer model, the value in supplier_relation property will be also added to the customer_relation property of this model.
Main question: Why does Betty Blocks give me this behaviour although te relations are unique by naming.
Secondary question:
I think this can be solved in two ways:
- Use a has and belongs to many relationship on the Relation model itself. But in this case I can't save additional detail about each link between the supplier-relation and customer-relation. For example "preferred supplier".
- Split the relation model into two separate models. One for Suppliers and one for customers and use the link model SupplierCustomer between these models. But that require an additional model (and block) that has exact the same properties.
So Is there a more efficient way that will work in Betty Blocks?
Login to reply