
add relation without overwriting old relation
Hello,
An invoice can have many transactions. Now i found out its possible for a single transaction to pay an amount for multiple invoices. And i'm working on a solution for this problem.
So i created a model that contains the transaction_amounts and added a has belongs to transaction relation. I also added a transaction has many invoices relation.
I'm working on an action that imports invoices and transactions through a SOAP solution. I'm inside a loop over the transaction amounts in a response where i want to perform an update query that uses an uid to set the relation to the invoice. I'm updating the transaction object with a collection of 1 invoices. (1 invoices because i'm in a loop). In the logs a can see the correct invoice collection and the correct transaction object. Now i think that it's working, but only the relation to the last invoice remains because it's probably overwriting the relation created in the previous loop items.
It's also possible that i have to add another relation to an invoice that already has relations with transactions that comes from another reponse. So i really need a solution that adds the relation in a non destructive way.
Anyone got an idea, how to handle this?
Hello,
An invoice can have many transactions. Now i found out its possible for a single transaction to pay an amount for multiple invoices. And i'm working on a solution for this problem.
So i created a model that contains the transaction_amounts and added a has belongs to transaction relation. I also added a transaction has many invoices relation.
I'm working on an action that imports invoices and transactions through a SOAP solution. I'm inside a loop over the transaction amounts in a response where i want to perform an update query that uses an uid to set the relation to the invoice. I'm updating the transaction object with a collection of 1 invoices. (1 invoices because i'm in a loop). In the logs a can see the correct invoice collection and the correct transaction object. Now i think that it's working, but only the relation to the last invoice remains because it's probably overwriting the relation created in the previous loop items.
It's also possible that i have to add another relation to an invoice that already has relations with transactions that comes from another reponse. So i really need a solution that adds the relation in a non destructive way.
Anyone got an idea, how to handle this?
Login to reply