Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [Symfony2][Doctrine]Usuwanie translacji gedmo, Gdy usuwamy rekord
marcio
post
Post #1





Grupa: Zarejestrowani
Postów: 2 291
Pomógł: 156
Dołączył: 23.09.2007
Skąd: ITALY-MILAN

Ostrzeżenie: (10%)
X----


Witam mam maly problem potrzebuje usunac wszystkie tlumaczenia z gedmo gdy usuwam jakis rekord.
Problem polega na tym ze nie moge uzywa dotakowych repozytoriow ani encji.
Wiec takie rozwiazanie odpada:
  • https://github.com/l3pp4rd/DoctrineExtensions/blob/master/doc/translatable.md#translation-entity
  • https://github.com/l3pp4rd/DoctrineExtensions/blob/master/doc/translatable.md#personal-translations

Poki co probowalem tak:
  1. /**
  2.   * Cleans texts of of the content with given ID
  3.   *
  4.   * @param integer $contentId ID of the content
  5.   * @return boolean
  6.   */
  7. public function cleanContent($contentId) {
  8. $content = $this->getContentById($contentId);
  9. if ($content !== null) {
  10. $translations = $this->getEntityManager()
  11. ->getRepository('Gedmo\Translatable\Entity\Translation')
  12. ->findBy(array(
  13. 'objectClass' => $this->getEntityClassName(),
  14. 'content' => $content->getContent()
  15. )
  16. );
  17.  
  18. foreach ($translations as $translation) {
  19. $this->getEntityManager()->remove($translation);
  20. }
  21. $content->setContent(null);
  22. $this->getEntityManager()->flush();
  23.  
  24. return true;
  25. }
  26.  
  27. return false;
  28. }

W translations znajduje sie:
Kod
Array ( [0] => Gedmo\Translatable\Entity\Translation Object ( [id:protected] => 1 [locale:protected] => pl_PL [objectClass:protected] => Meritoo\Cmf\PagesContentBundle\Entity\PagesContent [field:protected] => title [foreignKey:protected] => 1 [content:protected] => Strona główna ) [1] => Gedmo\Translatable\Entity\Translation Object ( [id:protected] => 3 [locale:protected] => en_GB [objectClass:protected] => Meritoo\Cmf\PagesContentBundle\Entity\PagesContent [field:protected] => title [foreignKey:protected] => 1 [content:protected] => Strona główna ) [2] => Gedmo\Translatable\Entity\Translation Object ( [id:protected] => 5 [locale:protected] => de_DE [objectClass:protected] => Meritoo\Cmf\PagesContentBundle\Entity\PagesContent [field:protected] => title [foreignKey:protected] => 1 [content:protected] => Strona główna ) [3] => Gedmo\Translatable\Entity\Translation Object ( [id:protected] => 7 [locale:protected] => fr_FR [objectClass:protected] => Meritoo\Cmf\PagesContentBundle\Entity\PagesContent [field:protected] => title [foreignKey:protected] => 1 [content:protected] => Strona główna ) [4] => Gedmo\Translatable\Entity\Translation Object ( [id:protected] => 9 [locale:protected] => en_US [objectClass:protected] => Meritoo\Cmf\PagesContentBundle\Entity\PagesContent [field:protected] => title [foreignKey:protected] => 1 [content:protected] => Strona główna ) )

Czyli mamy encje Translation wiec dlaczego remove nie dziala?
Zero bledow kompletnie nic a w bazie tlumaczenia dalej sa.
Czy ktos wie jak rozwiazac problem?
Go to the top of the page
+Quote Post
ano
post
Post #2





Grupa: Zarejestrowani
Postów: 435
Pomógł: 40
Dołączył: 16.02.2003
Skąd: Wrocław

Ostrzeżenie: (0%)
-----


Skoro masz 'tłumaczalny' model to nie mów, że nie ma on powiązania do encji tłumaczeń mniej więcej takiego:

  1. /**
  2.   * @ORM\OneToMany(
  3.   * targetEntity="CategoryTranslation",
  4.   * mappedBy="object",
  5.   * cascade={"persist", "remove"}
  6.   * )
  7.   */
  8. private $translations;


jeśli tak to usunięcie tej encji (EntityManager::remove(...)) spowoduje usunięcie również powiązanych translations. (zakładając, że masz zdefiniowaną operację kaskadową cascade={"remove"}).

Jeżeli tak nie masz to pytanie - czemu?

Cytat
Problem polega na tym ze nie moge uzywa dotakowych repozytoriow ani encji.

Dlaczego?
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 16.10.2025 - 23:51