Saving Contact $bean deletes email addresses

In the after_save logic hook for Accounts I wrote some code that would change the primary address of all Contacts linked to that account to the billing address of that account.

The code works, but we eventually noticed, the the mystery of vanishing email-addresses was directly related to that code I wrote:

$bean->load_relationship('contacts');
foreach ($bean->contacts->getBeans() as $contact){
   ...
  $contact->primary_address_street = $bean->billing_address_street;
  ...
  $contact->save();
}

The intended changes appear, but all linked contacts lose their email addresses.


Any ideas on how to convince $contact->save() to indeed save everything?
Parents Reply Children
No Data