SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Location
    Porto,Portugal
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Model OOP Inheritance in database

    Hi.
    What is the best way to model OOP Inheritance to an relational database?

    For example, I am working in a site for a fantasy soccer team. I have a games class that will have attributes like date, home team, away team, result etc.

    That i will have the class championship game,cup game and friendly game which can extend the game class which will have some extra attributes like round for cup games or team country for friendly games.

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Code:
    GAMES: id, date, home_team, away_team, result, type [championship, cup, friendly]
    
    CHAMPIONSHIP_GAME: game_id, championship_name
    
    CUP_GAME: game_id, round
    
    FRIENDLY_GAME: game_id, team_country

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Location
    Porto,Portugal
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. It works.

    But now i have another problem:
    I want to use Transactions when inserting into parent and child tables.
    So after insert into Games class and try to insert into friendly_game class if an error happens the first insert would be rollback.

    I am using pdo. How can i use transactions between insert methods in two different classes?

    I tried to return the connection in the insert method of the main game class to the subclasses and then use that connection to perform the other insert but if i try a rollback in dont work (inserts in the db).

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,151
    Mentioned
    16 Post(s)
    Tagged
    3 Thread(s)
    Are the tables a engine type that support transactions?

  5. #5
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Location
    Porto,Portugal
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have find that my tables engime is myISAM and doesnt support transactions.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •