Skip to content

Instantly share code, notes, and snippets.

@Bendihossan
Created October 12, 2012 13:20
Show Gist options
  • Save Bendihossan/3879169 to your computer and use it in GitHub Desktop.
Save Bendihossan/3879169 to your computer and use it in GitHub Desktop.
related content
/**
* @param ArrayCollection $related Related item
*/
public function setRelated(ArrayCollection $related)
{
$this->related = $related;
foreach ($related as $relation) {
if (! $relation->getRelated()->contains($this)) {
$relation->addRelation($this);
}
}
}
// The addRelation($relation) method simply adds the relation to the related property:
$this->related[] = $relation;
//...and checks to see if the inverse relation needs to be added:
if (! $relation->getRelated()->contains($this)) {
$relation->addRelation($this);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment