[Symfony] Klucze obce nazewnictwo |
[Symfony] Klucze obce nazewnictwo |
9.10.2019, 10:00:01
Post
#1
|
|
Grupa: Zarejestrowani Postów: 35 Pomógł: 0 Dołączył: 5.04.2017 Ostrzeżenie: (0%) |
Cześć
Tworzę projekt w Symfony 4.3 Kod php bin/console make:entity Post php bin/console make:entity Akapit field name post field type relation related to Post relation type ManyToOne new field name in Post akapity Później po Kod php bin/console make:migration php bin/console doctrine:migrations:migrate W bazie w tabeli akapit pojawia się pole `post_id` zamiast pola `post` W przypadku gdy przy make:entity podaję field name jako `post_id` to później w bazie pojawia się pole `post_id_id` Ma ktoś pomysł czemu to się tak rozjeżdża? Co innego w kodzie a co innego w bazie i później errory |
|
|
9.10.2019, 10:14:08
Post
#2
|
|
Grupa: Moderatorzy Postów: 36 446 Pomógł: 6292 Dołączył: 27.12.2004 |
Nom, jest to domyslne zachowanie w symfony/doctrine i jak najbardziej prawidlowe. Piszesz, ze masz z tego powodu problemy? Jakie jesli mozna spytac bo ja nigdy na takowe nie trafilem
-------------------- "Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista "Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer |
|
|
15.10.2019, 09:07:31
Post
#3
|
|
Grupa: Zarejestrowani Postów: 35 Pomógł: 0 Dołączył: 5.04.2017 Ostrzeżenie: (0%) |
A może i tak. Widocznie z innych przyczyn.
A na formularz z możliwością wyboru innej encji jaki miałbyś pomysł? Chcę dodawać posty do różnych tematów. Jest kilka tematów głównych i jak dodaję posta to wybieram z listy dostępnych tematów którego tematu ma dotyczyć. ManyToMany poniewać post może też być wyświetlany na stronach różnych tematów. Could not determine access type for property "tematy" in class "App\Entity\Post": The property "tematy" in class "App\Entity\Post" can be defined with the methods "addTematy()", "removeTematy()" but the new value must be an array or an instance of \Traversable, "App\Entity\Temat" given. Kod class PostType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('tematy', EntityType::class, [ 'label' => 'Tematy', 'class' => Temat::class, 'choice_label' => 'nazwa', ]) ->add('tytul', EntityType::class, [ 'class' => Tytul::class, /*'query_builder' => function (EntityRepository $er) { return $er->createQueryBuilder('t') ->orderBy('t.tresc', 'ASC'); },*/ /*'choice_label' => function($tytul) { return $tytul->getTresc(); },*/ 'multiple' => false, 'expanded' => false ]); } Kod class Post { /** * @ORM\Id() * @ORM\GeneratedValue() * @ORM\Column(type="integer") */ private $id; /** * @ORM\OneToMany(targetEntity="App\Entity\Akapit", mappedBy="post") */ private $akapity; /** * @ORM\OneToMany(targetEntity="App\Entity\Tabela", mappedBy="post") */ private $tabele; /** * @ORM\ManyToMany(targetEntity="App\Entity\Temat", inversedBy="posty") * @ORM\JoinTable(name="post_temat") */ private $tematy; /** * @ORM\ManyToOne(targetEntity="App\Entity\Tytul", inversedBy="posty", cascade={"persist"}) */ private $tytul; Kod /** * @Route("/new", name="post_new", methods={"GET","POST"}) */ public function new(Request $request): Response { $post = new Post(); $form = $this->createForm(PostType::class, $post); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $entityManager = $this->getDoctrine()->getManager(); $entityManager->persist($post); $entityManager->flush(); return $this->redirectToRoute('post_index'); } return $this->render('post/new.html.twig', [ 'post' => $post, 'form' => $form->createView(), ]); } Kod temat
id nazwa ||| | ||| post id elementy / | \ --------- | ------------- / | \ / | \ / | \ /// | \\\ ---\ wiersz ---------- akapit --------- tytuł ------------- tabela id ---/ id id id id_akapitu id_posta id_posta treść treść odstępg odstępg odstępg odstępp odstępp odstępp odstępd odstępd odstępd odstępl odstępl odstępl czcionka czcionka czcionka rozmiar rozmiar rozmiar pochylenie pochylenie pochylenie pogrubienie pogrubienie pogrubienie Ten post edytował ProgXT 15.10.2019, 13:21:22 |
|
|
Wersja Lo-Fi | Aktualny czas: 19.04.2024 - 03:23 |