Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [Symfony][Doctrine] Jak zdefiniować relacje
MacDada
post 22.09.2010, 06:40:43
Post #1





Grupa: Zarejestrowani
Postów: 47
Pomógł: 1
Dołączył: 24.06.2010
Skąd: Sopot

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


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.
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 1)
l3l0
post 22.09.2010, 12:10:26
Post #2





Grupa: Zarejestrowani
Postów: 94
Pomógł: 16
Dołączył: 24.07.2009
Skąd: Gdańsk

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


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
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 Wersja Lo-Fi Aktualny czas: 19.07.2025 - 09:47