protected function addAssociation(Association $association, Entity $subject, Entity $target, $target_property = null, $inversed_by = null, $is_owning_association = null)
 {
     $association->setSourceEntity($subject);
     $association->setTargetEntity($target);
     $association->setTargetPropertyName($target_property);
     $association->setInversedByPropertyName($inversed_by);
     if ($is_owning_association === true) {
         $association->setIsOwningAssociation(true);
     } else {
         if ($is_owning_association === false) {
             $association->setIsOwnedByAssociation(true);
         }
     }
     $subject->getAssociations()->add($association);
 }
示例#2
0
 public function associateOneToOne(Association $association, Entry $entry, Entry $associatedEntry)
 {
     // First create the owning entry association
     $oneAssociation = $entry->getAssociation($association->getTargetPropertyName());
     if (!is_object($oneAssociation)) {
         $oneAssociation = new Entry\OneAssociation();
         $oneAssociation->setAssociation($association);
         $oneAssociation->setEntry($entry);
     } else {
         // We clear out the one association
         $oneAssociation->getSelectedEntriesCollection()->remove(0);
     }
     $oneAssociation->setSelectedEntry($associatedEntry);
     $this->entityManager->persist($oneAssociation);
     $oneAssociation = $associatedEntry->getAssociation($association->getInversedByPropertyName());
     if (!is_object($oneAssociation)) {
         $inversedAssocation = $this->entityManager->getRepository('Concrete\\Core\\Entity\\Express\\Association')->findOneBy(['target_property_name' => $association->getInversedByPropertyName()]);
         $oneAssociation = new Entry\OneAssociation();
         $oneAssociation->setAssociation($inversedAssocation);
     } else {
         // We clear out the one association
         $oneAssociation->getSelectedEntriesCollection()->remove(0);
     }
     $oneAssociation->setEntry($associatedEntry);
     $oneAssociation->setSelectedEntry($entry);
     $this->entityManager->persist($oneAssociation);
     $this->entityManager->flush();
 }