Showing
7 changed files
with
23 additions
and
8 deletions
1 | class Group < ApplicationRecord | 1 | class Group < ApplicationRecord |
2 | - belongs_to :user, -> { with_deleted }, inverse_of: :groups | ||
3 | belongs_to :pool, -> { with_deleted }, inverse_of: :groups | 2 | belongs_to :pool, -> { with_deleted }, inverse_of: :groups |
3 | + has_and_belongs_to_many :users, inverse_of: :groups | ||
4 | + | ||
5 | + validates :name, :pool, presence: true | ||
4 | end | 6 | end | ... | ... |
... | @@ -17,7 +17,6 @@ class Pool < ApplicationRecord | ... | @@ -17,7 +17,6 @@ class Pool < ApplicationRecord |
17 | 17 | ||
18 | has_many :matches, dependent: :destroy, inverse_of: :pool | 18 | has_many :matches, dependent: :destroy, inverse_of: :pool |
19 | has_many :groups, inverse_of: :pool | 19 | has_many :groups, inverse_of: :pool |
20 | - has_many :users, through: :groups, inverse_of: :pools | ||
21 | 20 | ||
22 | scope :active, -> { where(active: true) } | 21 | scope :active, -> { where(active: true) } |
23 | accepts_nested_attributes_for :matches, reject_if: :all_blank, | 22 | accepts_nested_attributes_for :matches, reject_if: :all_blank, | ... | ... |
... | @@ -27,8 +27,7 @@ class User < ApplicationRecord | ... | @@ -27,8 +27,7 @@ class User < ApplicationRecord |
27 | before_save :encrypt_password | 27 | before_save :encrypt_password |
28 | 28 | ||
29 | has_many :bets, inverse_of: :user | 29 | has_many :bets, inverse_of: :user |
30 | - has_many :groups, inverse_of: :user | 30 | + has_and_belongs_to_many :groups, inverse_of: :users |
31 | - has_many :pools, through: :groups, inverse_of: :users | ||
32 | 31 | ||
33 | has_and_belongs_to_many :roles, inverse_of: :users, | 32 | has_and_belongs_to_many :roles, inverse_of: :users, |
34 | class_name: 'HeimdallEngine::Role', | 33 | class_name: 'HeimdallEngine::Role', | ... | ... |
1 | class CreateGroups < ActiveRecord::Migration[5.0] | 1 | class CreateGroups < ActiveRecord::Migration[5.0] |
2 | def change | 2 | def change |
3 | create_table :groups do |t| | 3 | create_table :groups do |t| |
4 | - t.integer :user_id, index: true | ||
5 | t.integer :pool_id, index: true | 4 | t.integer :pool_id, index: true |
5 | + t.string :name | ||
6 | t.timestamps | 6 | t.timestamps |
7 | end | 7 | end |
8 | end | 8 | end | ... | ... |
... | @@ -10,7 +10,7 @@ | ... | @@ -10,7 +10,7 @@ |
10 | # | 10 | # |
11 | # It's strongly recommended that you check this file into your version control system. | 11 | # It's strongly recommended that you check this file into your version control system. |
12 | 12 | ||
13 | -ActiveRecord::Schema.define(version: 20180611152223) do | 13 | +ActiveRecord::Schema.define(version: 20180611152633) do |
14 | 14 | ||
15 | # These are extensions that must be enabled in order to support this database | 15 | # These are extensions that must be enabled in order to support this database |
16 | enable_extension "plpgsql" | 16 | enable_extension "plpgsql" |
... | @@ -24,13 +24,19 @@ ActiveRecord::Schema.define(version: 20180611152223) do | ... | @@ -24,13 +24,19 @@ ActiveRecord::Schema.define(version: 20180611152223) do |
24 | t.integer "points" | 24 | t.integer "points" |
25 | end | 25 | end |
26 | 26 | ||
27 | - create_table "groups", force: :cascade do |t| | 27 | + create_table "group_users", force: :cascade do |t| |
28 | + t.integer "group_id" | ||
28 | t.integer "user_id" | 29 | t.integer "user_id" |
30 | + t.index ["group_id"], name: "index_group_users_on_group_id", using: :btree | ||
31 | + t.index ["user_id"], name: "index_group_users_on_user_id", using: :btree | ||
32 | + end | ||
33 | + | ||
34 | + create_table "groups", force: :cascade do |t| | ||
29 | t.integer "pool_id" | 35 | t.integer "pool_id" |
36 | + t.string "name" | ||
30 | t.datetime "created_at", null: false | 37 | t.datetime "created_at", null: false |
31 | t.datetime "updated_at", null: false | 38 | t.datetime "updated_at", null: false |
32 | t.index ["pool_id"], name: "index_groups_on_pool_id", using: :btree | 39 | t.index ["pool_id"], name: "index_groups_on_pool_id", using: :btree |
33 | - t.index ["user_id"], name: "index_groups_on_user_id", using: :btree | ||
34 | end | 40 | end |
35 | 41 | ||
36 | create_table "heimdall_engine_role_abilities", force: :cascade do |t| | 42 | create_table "heimdall_engine_role_abilities", force: :cascade do |t| | ... | ... |
-
Please register or login to post a comment