Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [SF2][Symfony2][Symfony] Zapis encji w relacji, Zapis z poziomu kontrolera
damianooo
post
Post #1





Grupa: Zarejestrowani
Postów: 496
Pomógł: 2
Dołączył: 15.07.2011
Skąd: Katowice

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


Czemu ponizszy zapis danych do bazy nie dziala ?

  1. public function createAction(){
  2.  
  3. $type = new Type();
  4. $match = new Match();
  5. $match->getId(3);
  6. $type->setNumberOfPoints(0);
  7. $type->setUser($this->getUser());
  8. $type->setMatch($match);
  9. $em = $this->getDoctrine()->getManager();
  10. $em->persist($type);
  11. $em->flush();
  12.  
  13. }


Blad ktory otrzymyje jest nastepujacy:

  1. A new entity was found through the relationship 'My\TyperkaBundle\Entity\Type#match' that was not configured to cascade persist operations for entity: . To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity or configure cascade persist this association in the mapping for example @ManyToOne(..,cascade={"persist"}).


Relacje miedzy encja Type i Match mam taka:

  1. // Type.php
  2.  
  3. class Type {
  4.  
  5. /**
  6.   * @ORM\ManyToOne(
  7.   * targetEntity = "Match",
  8.   * )
  9.   *
  10.   * @ORM\JoinColumn(
  11.   * name = "match_id",
  12.   * referencedColumnName = "id",
  13.   * onDelete = "SET NULL"
  14.   * )
  15.   */
  16. private $match;

Go to the top of the page
+Quote Post

Posty w temacie


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: 23.08.2025 - 17:14