Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [Symfony][Doctrine] CRUD dodający Null zamiast wartości pola
zniviash
post
Post #1





Grupa: Zarejestrowani
Postów: 7
Pomógł: 0
Dołączył: 13.09.2011

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


Witam,
wygenerowałem domyślnego CRUD'a dla tabeli użytkownika. W tabeli znajduje się również id użytkownika który polecił serwis(idpolecajacy).
zmieniłem __toString, user'a, i ładnie wyświetla wszystkich użytkowników w domyślnym formularzu. Początkowo w schema.yml nie ustawiłem notnull (dla pola idpolecajacy), i każda próba stworzenia nowego user'a kończyła się powodzeniem z małym ALE, w idpolecajacy wstawiany był NULL. Jeżeli użytkownik był edytowany, wszystkie dane można było zmienić, poza idpolecajacy. potem ustawiłem not null (jak w poniższym listingu), od tej pory symfony zaczął sypać błędem:
  1. 500 | Internal Server Error | Doctrine_Connection_Mysql_Exception
  2. SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'idpolecajacy' cannot be null
  3.  
  4. stack trace
  5. at ()
  6. in SF_SYMFONY_LIB_DIR\plugins\sfDoctrinePlugin\lib\vendor\doctrine\Doctrine\Connect
    ion.php line 1082 ...
  7. $message .= sprintf('. Failing Query: "%s"', $query);
  8.  
  9. }
  10.  
  11.  
  12. $exc = new $name($message, (int) $e->getCode());
  13.  
  14. if ( ! isset($e->errorInfo) || ! is_array($e->errorInfo)) {
  15.  
  16. $e->errorInfo = array(null, null, null, null);
  17.  
  18. }
  19. at Doctrine_Connection->rethrowException(object('PDOException'), object('Doctrine_Connection_Statement'))
  20. in SF_SYMFONY_LIB_DIR\plugins\sfDoctrinePlugin\lib\vendor\doctrine\Doctrine\Connect
    ion\Statement.php line 269 ...
  21. at Doctrine_Connection_Statement->execute(array('zdzichu', 'zdzichu@mail.mail', 'tajnehaslo', null))
  22. in SF_SYMFONY_LIB_DIR\plugins\sfDoctrinePlugin\lib\vendor\doctrine\Doctrine\Connect
    ion.php line 1042 ...
  23. at Doctrine_Connection->exec('INSERT INTO user (nick, email, haslo, idpolecajacy) VALUES (?, ?, ?, ?)', array('zdzichu', 'zdzichu@mail.mail', 'tajnehaslo', null))
  24. in SF_SYMFONY_LIB_DIR\plugins\sfDoctrinePlugin\lib\vendor\doctrine\Doctrine\Connect
    ion.php line 687 ...
  25. at Doctrine_Connection->insert(object('userTable'), array('nick' => 'zdzichu', 'email' => 'zdzichu@mail.mail', 'haslo' => 'tajnehaslo', 'idpolecajacy' => null))
  26. in SF_SYMFONY_LIB_DIR\plugins\sfDoctrinePlugin\lib\vendor\doctrine\Doctrine\Connect
    ion\UnitOfWork.php line 647 ...
  27. at Doctrine_Connection_UnitOfWork->processSingleInsert(object('user'))
  28. in SF_SYMFONY_LIB_DIR\plugins\sfDoctrinePlugin\lib\vendor\doctrine\Doctrine\Connect
    ion\UnitOfWork.php line 571 ...
  29. at Doctrine_Connection_UnitOfWork->insert(object('user'))
  30. in SF_SYMFONY_LIB_DIR\plugins\sfDoctrinePlugin\lib\vendor\doctrine\Doctrine\Connect
    ion\UnitOfWork.php line 81 ...
  31. at Doctrine_Connection_UnitOfWork->saveGraph(object('user'))
  32. in SF_SYMFONY_LIB_DIR\plugins\sfDoctrinePlugin\lib\vendor\doctrine\Doctrine\Record.php line 1718 ...
  33. at Doctrine_Record->save(object('Doctrine_Connection_Mysql'))
  34. in SF_SYMFONY_LIB_DIR\form\addon\sfFormObject.class.php line 161 ...
  35. at sfFormObject->doSave(object('Doctrine_Connection_Mysql'))
  36. in SF_SYMFONY_LIB_DIR\form\addon\sfFormObject.class.php line 130 ...
  37. at sfFormObject->save()
  38. in SF_ROOT_DIR\apps\frontend\modules\user\actions\actions.class.php line 74 ...
  39. at userActions->processForm(object('sfWebRequest'), object('userForm'))
  40. in SF_ROOT_DIR\apps\frontend\modules\user\actions\actions.class.php line 37 ...
  41. at userActions->executeCreate(object('sfWebRequest'))
  42. in SF_SYMFONY_LIB_DIR\action\sfActions.class.php line 60 ...
  43. at sfActions->execute(object('sfWebRequest'))
  44. in SF_SYMFONY_LIB_DIR\filter\sfExecutionFilter.class.php line 92 ...
  45. at sfExecutionFilter->executeAction(object('userActions'))
  46. in SF_SYMFONY_LIB_DIR\filter\sfExecutionFilter.class.php line 78 ...
  47. at sfExecutionFilter->handleAction(object('sfFilterChain'), object('userActions'))
  48. in SF_SYMFONY_LIB_DIR\filter\sfExecutionFilter.class.php line 42 ...
  49. at sfExecutionFilter->execute(object('sfFilterChain'))
  50. in SF_SYMFONY_LIB_DIR\filter\sfFilterChain.class.php line 53 ...
  51. at sfFilterChain->execute()
  52. in SF_SYMFONY_LIB_DIR\filter\sfRenderingFilter.class.php line 33 ...
  53. at sfRenderingFilter->execute(object('sfFilterChain'))
  54. in SF_SYMFONY_LIB_DIR\filter\sfFilterChain.class.php line 53 ...
  55. at sfFilterChain->execute()
  56. in SF_SYMFONY_LIB_DIR\controller\sfController.class.php line 238 ...
  57. at sfController->forward('user', 'create')
  58. in SF_SYMFONY_LIB_DIR\controller\sfFrontWebController.class.php line 48 ...
  59. at sfFrontWebController->dispatch()
  60. in SF_SYMFONY_LIB_DIR\util\sfContext.class.php line 170 ...
  61. at sfContext->dispatch()
  62. in SF_ROOT_DIR\web\frontend_dev.php line 13 ...


schema.yml wygląda następująco:

  1. ---
  2. detect_relations: true
  3. options:
  4. collate: utf8_polish_ci
  5. charset: utf8
  6. type: InnoDB
  7.  
  8. user:
  9. columns:
  10. iduser:
  11. type: integer(4)
  12. primary: true
  13. notnull: true
  14. autoincrement: true
  15. nick:
  16. type: string(45)
  17. notnull: true
  18. email:
  19. type: string(256)
  20. notnull: true
  21. haslo:
  22. type: string(128)
  23. notnull: true
  24. idpolecajacy:
  25. type: integer(4)
  26. notnull: true
  27. relations:
  28. idpolecajacy:
  29. class: user
  30. local: idpolecajacy
  31. foreign: iduser
  32. foreignAlias: users
  33. indexes:
  34. fk_user_user1:
  35. fields: [idpolecajacy]


formularz był poprawnie generowany i każdy idpolecajacy w comboboxie miał odpowiednią wartość oraz etykietę,
tablica POST też przyjmowała odpowiednią wartość dla tego pola.

jestem początkującym w tym frameworku, a tu takie schody :]

wersja symfony: 1.4.13

bardzo proszę o pomoc/sugestie, może zapomniałem o czymś? tego typu CRUD powinien chyba działać od razu po zmianie funkcji __tostring?

ps.
symfony generuje takiego inserta:
  1. INSERT INTO user (nick, email, haslo, idpolecajacy) VALUES (?, ?, ?, ?) - (zdzichu, zdzichu@mail.mail, tajnehaslo, )

zupełnia pomija idpolecajacy, dlaczego ta wartość się gubi?

Ten post edytował zniviash 13.09.2011, 08:31:43
Go to the top of the page
+Quote Post
Valantir
post
Post #2





Grupa: Zarejestrowani
Postów: 93
Pomógł: 7
Dołączył: 6.09.2011
Skąd: Olsztyn

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


Nie wiem czy pomogę, bo też jestem początkujący... Daj plik akcji.

Ten post edytował Valantir 13.09.2011, 11:35:46


--------------------
Pomogłem? Kliknij "Pomógł".
Go to the top of the page
+Quote Post
zniviash
post
Post #3





Grupa: Zarejestrowani
Postów: 7
Pomógł: 0
Dołączył: 13.09.2011

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


akcja jest nie ruszana, świeżo wygenerowana.

  1. <?php
  2.  
  3. /**
  4.  * user actions.
  5.  *
  6.  * @package temp1
  7.  * @subpackage user
  8.  * @author Your name here
  9.  * @version SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
  10.  */
  11. class userActions extends sfActions
  12. {
  13. public function executeIndex(sfWebRequest $request)
  14. {
  15. $this->users = Doctrine_Core::getTable('User')
  16. ->createQuery('a')
  17. ->execute();
  18. }
  19.  
  20. public function executeNew(sfWebRequest $request)
  21. {
  22. $this->form = new UserForm();
  23. }
  24.  
  25. public function executeCreate(sfWebRequest $request)
  26. {
  27. $this->forward404Unless($request->isMethod(sfRequest::POST));
  28.  
  29. $this->form = new UserForm();
  30.  
  31. $this->processForm($request, $this->form);
  32.  
  33. $this->setTemplate('new');
  34. }
  35.  
  36. public function executeEdit(sfWebRequest $request)
  37. {
  38. $this->forward404Unless($user = Doctrine_Core::getTable('User')->find(array($request->getParameter('iduser'))), sprintf('Object user does not exist (%s).', $request->getParameter('iduser')));
  39. $this->form = new UserForm($user);
  40. }
  41.  
  42. public function executeUpdate(sfWebRequest $request)
  43. {
  44. $this->forward404Unless($request->isMethod(sfRequest::POST) || $request->isMethod(sfRequest::PUT));
  45. $this->forward404Unless($user = Doctrine_Core::getTable('User')->find(array($request->getParameter('iduser'))), sprintf('Object user does not exist (%s).', $request->getParameter('iduser')));
  46. $this->form = new UserForm($user);
  47.  
  48. $this->processForm($request, $this->form);
  49.  
  50. $this->setTemplate('edit');
  51. }
  52.  
  53. public function executeDelete(sfWebRequest $request)
  54. {
  55. $request->checkCSRFProtection();
  56.  
  57. $this->forward404Unless($user = Doctrine_Core::getTable('User')->find(array($request->getParameter('iduser'))), sprintf('Object user does not exist (%s).', $request->getParameter('iduser')));
  58. $user->delete();
  59.  
  60. $this->redirect('user/index');
  61. }
  62.  
  63. protected function processForm(sfWebRequest $request, sfForm $form)
  64. {
  65. $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
  66. if ($form->isValid())
  67. {
  68. $user = $form->save();
  69.  
  70. $this->redirect('user/edit?iduser='.$user->getIduser());
  71. }
  72. }
  73. }
Go to the top of the page
+Quote Post
Valantir
post
Post #4





Grupa: Zarejestrowani
Postów: 93
Pomógł: 7
Dołączył: 6.09.2011
Skąd: Olsztyn

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


Myślałem, że może coś zmieniałeś... Szczerze? Zaczyna mnie bardzo nurtować Twój problem, tym bardziej, że sam takiego nie miałem ale zawsze może wyskoczyć w najmniej odpowiednim momencie. Skoro zmieniałeś plik schema to wyczyściłeś cache? Może to coś da..

Ten post edytował Valantir 13.09.2011, 12:39:09


--------------------
Pomogłem? Kliknij "Pomógł".
Go to the top of the page
+Quote Post
zniviash
post
Post #5





Grupa: Zarejestrowani
Postów: 7
Pomógł: 0
Dołączył: 13.09.2011

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


zrobiłem nowy projekt, od zera, tylko po to by to przetestować.
może coś robię nie tak?
przede wszystkim schema jest ok?

robię tak:
ustawiam pass dla bazy danych
wstawiam to co w listingu do schma.yml
doctrine:build --all
doctrine:generate-module frontend user User

potem ewentualnie w pliku user.class.php:

  1. class user extends Baseuser
  2. {
  3. public function __toString() {
  4. return $this->getEmail();
  5. }
  6. }

czy jeszcze powinienem coś zrobić żeby ten crud zaczął działać?

stworzyłem projekt na wersji 1.4.5 i to samo ;/
Go to the top of the page
+Quote Post
Valantir
post
Post #6





Grupa: Zarejestrowani
Postów: 93
Pomógł: 7
Dołączył: 6.09.2011
Skąd: Olsztyn

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


Ja używam propel ale w tym przypadku chyba nie ma dużej różnicy. Zgłasza mi błędy w schema więc to jest chyba do poprawy... sprawdź przez np phpmyadmin czy dobrze masz bazę sklepaną.
Ja używam takiego zapisu:

Kod
propel:    <----u Ciebie inaczej.
  katedra:
    katedra_id:                          { type: integer, required: true, primaryKey: true, autoIncrement: true }
    nazwa:                               { type: varchar(45), primaryString: true }
    skrot:                               { type: varchar(20) }
    slug:                                { type: varchar(128) }
    wydzial_id:                          { type: integer, onDelete: cascade, foreignTable: wydzial, foreignReference: wydzial_id }
    _indexes:
      fk_katedra_wydzial:                [ wydzial_id ]
    _uniques:
      u_slug:                            [ slug ]
.
.
.
itd



--------------------
Pomogłem? Kliknij "Pomógł".
Go to the top of the page
+Quote Post
zniviash
post
Post #7





Grupa: Zarejestrowani
Postów: 7
Pomógł: 0
Dołączył: 13.09.2011

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


problem oczywiście tkwił w schema:) tak czułem.
plik miałem wygenerowany z mysql workbench, i myślałem że jest ok.

dziękuję za zainteresowanie problemem i przepraszam za zawracanie głowy.
muszę znaleźć jakąś ciekawą lekturę dot mysql workbench
Go to the top of the page
+Quote Post

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

 



RSS Aktualny czas: 19.08.2025 - 17:00