http://guides.rubyonrails.org/association_basics.html#the-has_many-through-association

могу дать составной первичный ключ в Rails без каких-либо драгоценных камней?

Моя первая таблица в файле миграции:

class CreateUsers < ActiveRecord::Migration
  def self.up
    create_table :users do |t|
      t.string :userid
      t.string :name
      t.string :address
      t.timestamps
    end
  end

  def self.down
    drop_table :users
  end
end

Моя вторая таблица в файле миграции:

class CreateProjects < ActiveRecord::Migration
  def self.up
    create_table :projects do |t|
      t.string :title
      t.string :description
      t.timestamps
    end
  end
  def self.down
    drop_table :projects
  end
end

В моем файле схемы:

ActiveRecord::Schema.define(:version => 20110222044146) do
  create_table "projects", :force => true do |t|
    t.string   "title"
    t.string   "description"
    t.datetime "created_at"
    t.datetime "updated_at"
  end

  create_table "users", :force => true do |t|
    t.string   "userid"
    t.string   "name"
    t.string   "address"
    t.datetime "created_at"
    t.datetime "updated_at"
  end
end

Теперь я хочу создать таблицу под названиемUser_has_project в котором я буду ссылаться на пользователя и проект, что означает, что будет иметь 2 внешних ключа. Итак, я попробовал так:

class CreateUser_has_projects < ActiveRecord::Migration
  def self.up
    create_table :user_has_projects do |t|
      t.references :User
      t.references :Project
      t.boolean :status
      t.timestamps
    end
  end

  def self.down
    drop_table :users
  end
end

Теперь, как я могу установить комбинацию user_id и project_id в качестве первичного ключа в user_has_projects?

Ответы на вопрос(1)

Ваш ответ на вопрос