Iker Narvaez

added group model

class Group < ApplicationRecord
belongs_to :user, -> { with_deleted }, inverse_of: :groups
belongs_to :pool, -> { with_deleted }, inverse_of: :groups
end
......@@ -16,6 +16,8 @@ class Pool < ApplicationRecord
validates :name, :editable_until, presence: true
has_many :matches, dependent: :destroy, inverse_of: :pool
has_many :groups, inverse_of: :pool
has_many :users, through: :groups, inverse_of: :pools
scope :active, -> { where(active: true) }
accepts_nested_attributes_for :matches, reject_if: :all_blank,
......
......@@ -27,6 +27,8 @@ class User < ApplicationRecord
before_save :encrypt_password
has_many :bets, inverse_of: :user
has_many :groups, inverse_of: :user
has_many :pools, through: :groups, inverse_of: :users
has_and_belongs_to_many :roles, inverse_of: :users,
class_name: 'HeimdallEngine::Role',
......
class CreateGroups < ActiveRecord::Migration[5.0]
def change
create_table :groups do |t|
t.integer :user_id, index: true
t.integer :pool_id, index: true
t.timestamps
end
end
end
......@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20180608221342) do
ActiveRecord::Schema.define(version: 20180611152223) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
......@@ -24,6 +24,15 @@ ActiveRecord::Schema.define(version: 20180608221342) do
t.integer "points"
end
create_table "groups", force: :cascade do |t|
t.integer "user_id"
t.integer "pool_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["pool_id"], name: "index_groups_on_pool_id", using: :btree
t.index ["user_id"], name: "index_groups_on_user_id", using: :btree
end
create_table "heimdall_engine_role_abilities", force: :cascade do |t|
t.integer "role_id"
t.string "key"
......
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
user_id: 1
pool_id: 1
two:
user_id: 1
pool_id: 1
require 'test_helper'
class GroupTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end