Skip to content

Instantly share code, notes, and snippets.

@smarek
Created August 26, 2019 08:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smarek/4eb45ff9abc64627dcf6d42301d3ebef to your computer and use it in GitHub Desktop.
Save smarek/4eb45ff9abc64627dcf6d42301d3ebef to your computer and use it in GitHub Desktop.
cakephp remove all associated fields from entity
<?php
public function entityStripAssociations(Entity &$entity)
{
/** @var Table $table */
$table = TableRegistry::getTableLocator()->get($entity->getSource());
foreach ($table->associations() as $asoc) {
$entity->unsetProperty($asoc->getProperty());
}
return $entity;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment