Association table with data


I have two tables : users and products. a user buy many products. so I want to save the quantity in the association table.

I do the following

    $userId = 1;
    $productId = 2;

    $usersProductsTable = TableRegistry::getTableLocator()->get('UsersProducts');
    $userProduct = $usersProductsTable->newEntity();

    // Remplir les champs de l'entité
    $userProduct->user_id = $userId;
    $userProduct->product_id = $productId;
    $userProduct->quantity = 3; // Ajoutez d'autres champs au besoin

but I find that uggly and I would like to do that on my entities object. what is the best way to do that.