Skip to content

Instantly share code, notes, and snippets.

@mAlishera
Created January 23, 2017 23:09
Show Gist options
  • Save mAlishera/89f98f30bc906595e9d3ce3a68bf040e to your computer and use it in GitHub Desktop.
Save mAlishera/89f98f30bc906595e9d3ce3a68bf040e to your computer and use it in GitHub Desktop.
Composite primary key with ActiveRecord
class CreateGroupChatVersion < ActiveRecord::Migration
def change
create_table :group_chat_versions, id: false do |t|
t.integer :version
t.uuid :group_chat_id
...
end
add_index :group_chat_versions, [:version, :group_chat_id], name: "group_chat_version_id"
end
end
...
gem 'composite_primary_keys', '=8.1.5'
...
class GroupChatVersion < ActiveRecord::Base
self.primary_keys = :version, :group_chat_id
belongs_to :group_chat
...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment