user1088417
user1088417

Reputation: 55

Many-to-Many models association, matrix table with additional fields

My database is structured with 3 tables: Product, Operation and a junction table Product_Operation for manage many to many relationship.

The junction table is defined with more than two columns, in that each 'association' has additional information such 'expiration_date' (each operation practible on a specific product can be done for a limited range of time). enter image description here

Obviously in ExtJs i've created the model Product and Operation, and managed the relationship according to the official documentation

    
    Ext.define
    (
        "myapp.model.Product",
        {
            extend: "Ext.data.Model",
            idProperty: "id",
            fields:
            [
                {
                    name: "id",
                    type: "integer"
                },
                {
                    name: "name",
                    type: "string"
                },
            ],
            manyToMany:
            {
                Product_Operation:
                {
                    type: "myapp.model.Operation",
                    role: "operations",
                    field: "id", //pk operation 
                    right:
                    {
                        field: "id", //pk product
                        role: "products",
                    }
                }
            }
        }
    );
    
    Ext.define
    (
        "myapp.model.Operation",
        {
            extend: "Ext.data.Model",
            idProperty: "id",
            fields:
            [
                {
                    name: "id",
                    type: "integer"
                },
                {
                    name: "name",
                    type: "string"
                }
            ]
        }
    );

But i noted that there's no way to map additional fields in what they call 'matrix table'. So, how can i manage my additional data coming from the junction table? There's a predefined way to do it with extjs framework itself?

Upvotes: 1

Views: 59

Answers (0)

Related Questions