Monday, 15 February 2010

ruby on rails - Trouble modelling a sports league in ActiveRecord -


Use the active record for the first time. I am looking for a small online-simulation game where I have free agency, player, team, season and post season schedule. Players should move from team to team and "compete" against each other. When I try to add all these classes together, then I am getting the problem with backcount errors, I have the structure at the moment:

Schema:

  Create_table "games", force :: waterfall do T | T.integer "visit_team" t.integer "home_team" t.integer "visit_score" t.integer "home_score" t.integer "winner" end create_table "league", force :: waterfall do. T | T.string "schedule" t.string "teams" t.string "player" end create_table "players", force :: waterfall do. T | T.string "name" t.string "position" t.integer "rating" t.integer "age" t.datetime "created_at" t.datetime "updated_at" t.integer "team_id" t.boolean "free_agent" end create_table "Program", Force :: Waterfall do. T | T.integer "game" end create_table "teams", force :: waterfall do | T | T.string "name" t.string "location" t.integer "wins" t.integer "losses" t.integer "rating" t.datetime "created_at" t.datetime "update_at" end  

And here are the links:

  The class team & lt; ActiveRecord :: Base has has_many (: player) has_many (: game) belong_to (: league) end class schedule & lt; ActiveRecord :: Base has_many (: Games) belong_to (: League) and Class Player & lt; ActiveRecord :: Base is_to (: Team) has_many (: Games) belong_to (: League) and Class League & lt; ActiveRecord :: Base_On (: schedule) has_many (: teams) has_many (: players) and class games & lt; Question: Do I need to add foreign key relationships for example between league and players / teams? Do not say documentation, but I can not understand how a player can relate to the league without reference to a primary / foreign key. Also, I am also unsure how to structure the schedule class. I'm not sure which features mean that I want to be able to compete for each team in many games and there is a schedule for each of them to be ready. I am a newbie, therefore, while pointing out the good resources for active resources (which do not fully understand the documents, besides), I would be very helpful! 


No comments:

Post a Comment