Iker Narvaez

added group model

1 +class Group < ApplicationRecord
2 + belongs_to :user, -> { with_deleted }, inverse_of: :groups
3 + belongs_to :pool, -> { with_deleted }, inverse_of: :groups
4 +end
...@@ -16,6 +16,8 @@ class Pool < ApplicationRecord ...@@ -16,6 +16,8 @@ class Pool < ApplicationRecord
16 validates :name, :editable_until, presence: true 16 validates :name, :editable_until, presence: true
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
20 + has_many :users, through: :groups, inverse_of: :pools
19 21
20 scope :active, -> { where(active: true) } 22 scope :active, -> { where(active: true) }
21 accepts_nested_attributes_for :matches, reject_if: :all_blank, 23 accepts_nested_attributes_for :matches, reject_if: :all_blank,
......
...@@ -27,6 +27,8 @@ class User < ApplicationRecord ...@@ -27,6 +27,8 @@ 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
31 + has_many :pools, through: :groups, inverse_of: :users
30 32
31 has_and_belongs_to_many :roles, inverse_of: :users, 33 has_and_belongs_to_many :roles, inverse_of: :users,
32 class_name: 'HeimdallEngine::Role', 34 class_name: 'HeimdallEngine::Role',
......
1 +class CreateGroups < ActiveRecord::Migration[5.0]
2 + def change
3 + create_table :groups do |t|
4 + t.integer :user_id, index: true
5 + t.integer :pool_id, index: true
6 + t.timestamps
7 + end
8 + end
9 +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: 20180608221342) do 13 +ActiveRecord::Schema.define(version: 20180611152223) 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,6 +24,15 @@ ActiveRecord::Schema.define(version: 20180608221342) do ...@@ -24,6 +24,15 @@ ActiveRecord::Schema.define(version: 20180608221342) do
24 t.integer "points" 24 t.integer "points"
25 end 25 end
26 26
27 + create_table "groups", force: :cascade do |t|
28 + t.integer "user_id"
29 + t.integer "pool_id"
30 + t.datetime "created_at", null: false
31 + t.datetime "updated_at", null: false
32 + 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
35 +
27 create_table "heimdall_engine_role_abilities", force: :cascade do |t| 36 create_table "heimdall_engine_role_abilities", force: :cascade do |t|
28 t.integer "role_id" 37 t.integer "role_id"
29 t.string "key" 38 t.string "key"
......
1 +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2 +
3 +one:
4 + user_id: 1
5 + pool_id: 1
6 +
7 +two:
8 + user_id: 1
9 + pool_id: 1
1 +require 'test_helper'
2 +
3 +class GroupTest < ActiveSupport::TestCase
4 + # test "the truth" do
5 + # assert true
6 + # end
7 +end