2012-03-17 78 views
0

我对轨道很陌生,正在构建一个简单的应用程序。导轨模型/数据库

  1. 用户可以通过另一个用户

目前,我有我的模型建立这样创建一个游戏

  • 用户可以加入创造了一个游戏: 用户 - 有许多游戏。 游戏 - 属于用户。

    数字1.在我的文章工作正常。

    但我该如何去实现数字2?

    数据库目前看起来是这样的:

    create_table "games", :force => true do |t| 
        t.integer "user_id" 
        t.datetime "created_at", :null => false 
        t.datetime "updated_at", :null => false 
    end 
    
    create_table "users", :force => true do |t| 
        t.string "name" 
        t.string "email" 
        t.datetime "created_at", :null => false 
        t.datetime "updated_at", :null => false 
    end 
    
  • +0

    我还没有尝试过任何东西,因为我不确定从哪里开始。 – steve 2012-03-17 17:35:04

    +0

    你没有阅读[this](http://stackoverflow.com/questions/how-to-ask)? – 2012-03-17 17:37:05

    +0

    [This this](http://msmvps.com/blogs/jon_skeet/archive/2010/08/29/writing-the-perfect-question.aspx)。 – 2012-03-17 17:40:47

    回答

    0

    我想你应该创建一个新的名为modelJoinGamebelongs_to Usermodel应是像

    class User < ActiveRecord::Base has_many :join_games end

    class JoinGame < ActiveRecord::Base belongs_to :user end

    通过这个你可以实现你想要的,然后你将不得不创建逻辑