2012-03-17 133 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

    通過這個你可以實現你想要的,然後你將不得不創建邏輯