Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [Symfony][Doctrine] Jak zdefiniować relacje
Forum PHP.pl > Forum > PHP > Frameworki
MacDada
Hej,

uczę się symfony i postanowiłem napisać prostą grę online. Nie bardzo jednak wiem, jak powinny wyglądać relacje między tabelami w bazie danych...

Plik schema.yml wygląda tak (zbędne wycięte):
http://paste-it.net/public/pb05a2f/c/

Pytanie brzmi, czy klasa Player ma dobrze zdefiniowane relacje? W tutorialu Jobeet jest taki fragment:
class: JobeetCategory
refClass: JobeetCategoryAffiliate
local: affiliate_id
foreign: category_id
foreignAlias: JobeetAffiliates

Co zmieniają dwie pierwsze linie, jeśli się je doda?

Z góry dzięki za odpowiedź,
pozdr.
l3l0
Witam,

Nie wiem czy dokładnie o to Ci chodzi, ale ta schema może być zdefiniowana między innymi w ten sposób:
  1. User:
  2. actAs: { Timestampable: ~ }
  3. columns:
  4. id { type: integer(4), autoincrement: true, primary: true }
  5. nickname: { type: string(255), notnull: true, unique: true }
  6. created_at: { type: timestamp, notnull: true }
  7. relations:
  8. PlayerCities:
  9. class: City #nazwa klasy z którą rekord ma się łączyć (jeśli inna niż nazwa)
  10. refClass: Player #nazwa klasy przez którą następuje złączenie (dla relacji typu "many")
  11. local: user_id #pole w relacji podanej w refClass
  12. foreign: city_id #pole w relacji podanej w refClass
  13. type: many
  14.  
  15. GameState:
  16. actAs: { Timestampable: ~ }
  17. columns:
  18. name: { type: string(255), notnull: true, unique: true }
  19.  
  20. City:
  21. actAs: { Timestampable: ~ }
  22. columns:
  23. name: { type: string(255), notnull: true, unique: true }
  24. game_state: { type: integer, notnull: true }
  25. created_by: { type: integer, notnull: true }
  26. created_at: { type: timestamp, notnull: true }
  27. relations:
  28. MafiaGameState: { class: GameState, local: game_state, foreign: id, foreignAlias: Cites }
  29. MafiaUser: { class: User, local: created_by, foreign: id, foreignAlias: CreatedCites }
  30. PlayingUsers: { class: User, refClass: Player, local: city_id, foreign: user_id, type: many }
  31.  
  32. Player:
  33. actAs: { Timestampable: ~ }
  34. columns:
  35. user_id: { type: integer, notnull: true }
  36. city_id: { type: integer, notnull: true }
  37. is_city_mayor: { type: boolean, notnull: true, default: 0 }
  38. relations:
  39. User: { class: User, local: user_id, foreign: id, foreignAlias: Players }
  40. City: { class: City, local: city_id, foreign: id, foreignAlias: Players }


Mam nadzieje że Ci to pomoże.

Pozdrawiam
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.