Created
January 23, 2017 23:09
-
-
Save mAlishera/89f98f30bc906595e9d3ce3a68bf040e to your computer and use it in GitHub Desktop.
Composite primary key with ActiveRecord
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
gem 'composite_primary_keys', '=8.1.5' | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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