finally commited the stuff I wrote 4 hours ago
This commit is contained in:
parent
ce7f896e0c
commit
5e26d72d91
|
@ -1,4 +1,12 @@
|
||||||
class Group < ActiveRecord::Base
|
class Group < ActiveRecord::Base
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
has_many :users
|
has_many :group_members, dependent: :destroy
|
||||||
|
|
||||||
|
before_validation do
|
||||||
|
self.name = self.display_name.downcase.sub(/\s+/, '-')
|
||||||
|
end
|
||||||
|
|
||||||
|
def add_member(user)
|
||||||
|
GroupMember.create! group: self, user: user
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
class GroupMember < ActiveRecord::Base
|
||||||
|
has_one :user
|
||||||
|
has_one :group
|
||||||
|
end
|
|
@ -26,7 +26,7 @@ class User < ActiveRecord::Base
|
||||||
has_many :moderation_comments, dependent: :destroy
|
has_many :moderation_comments, dependent: :destroy
|
||||||
has_many :moderation_votes, dependent: :destroy
|
has_many :moderation_votes, dependent: :destroy
|
||||||
has_many :groups, dependent: :destroy
|
has_many :groups, dependent: :destroy
|
||||||
belongs_to :group, foreign_key: :target_id
|
has_many :group_memberships, class_name: "GroupMember", dependent: :destroy
|
||||||
|
|
||||||
SCREEN_NAME_REGEX = /\A[a-zA-Z0-9_]{1,16}\z/
|
SCREEN_NAME_REGEX = /\A[a-zA-Z0-9_]{1,16}\z/
|
||||||
WEBSITE_REGEX = /https?:\/\/([A-Za-z.\-]+)\/?(?:.*)/i
|
WEBSITE_REGEX = /https?:\/\/([A-Za-z.\-]+)\/?(?:.*)/i
|
||||||
|
|
|
@ -2,16 +2,26 @@ class CreateGroups < ActiveRecord::Migration
|
||||||
def change
|
def change
|
||||||
create_table :groups do |t|
|
create_table :groups do |t|
|
||||||
t.integer :user_id, null: false
|
t.integer :user_id, null: false
|
||||||
t.integer :target_id, null: false
|
|
||||||
t.string :name
|
t.string :name
|
||||||
t.string :display_name
|
t.string :display_name
|
||||||
|
t.boolean :private, default: true
|
||||||
|
|
||||||
t.timestamps
|
t.timestamps
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index :groups, :user_id
|
add_index :groups, :user_id
|
||||||
add_index :groups, :target_id
|
|
||||||
add_index :groups, :name
|
add_index :groups, :name
|
||||||
add_index :groups, [:user_id, :name], unique: true
|
add_index :groups, [:user_id, :name], unique: true
|
||||||
|
|
||||||
|
create_table :group_members do |t|
|
||||||
|
t.integer :group_id, null: false
|
||||||
|
t.integer :user_id, null: false
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
|
||||||
|
add_index :group_members, :group_id
|
||||||
|
add_index :group_members, :user_id
|
||||||
|
add_index :group_members, [:group_id, :user_id], unique: true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
16
db/schema.rb
16
db/schema.rb
|
@ -38,17 +38,27 @@ ActiveRecord::Schema.define(version: 20150108121010) do
|
||||||
|
|
||||||
add_index "comments", ["user_id", "created_at"], name: "index_comments_on_user_id_and_created_at", using: :btree
|
add_index "comments", ["user_id", "created_at"], name: "index_comments_on_user_id_and_created_at", using: :btree
|
||||||
|
|
||||||
|
create_table "group_members", force: true do |t|
|
||||||
|
t.integer "group_id", null: false
|
||||||
|
t.integer "user_id", null: false
|
||||||
|
t.datetime "created_at"
|
||||||
|
t.datetime "updated_at"
|
||||||
|
end
|
||||||
|
|
||||||
|
add_index "group_members", ["group_id", "user_id"], name: "index_group_members_on_group_id_and_user_id", unique: true, using: :btree
|
||||||
|
add_index "group_members", ["group_id"], name: "index_group_members_on_group_id", using: :btree
|
||||||
|
add_index "group_members", ["user_id"], name: "index_group_members_on_user_id", using: :btree
|
||||||
|
|
||||||
create_table "groups", force: true do |t|
|
create_table "groups", force: true do |t|
|
||||||
t.integer "user_id", null: false
|
t.integer "user_id", null: false
|
||||||
t.integer "target_id", null: false
|
|
||||||
t.string "name"
|
t.string "name"
|
||||||
t.string "display_name"
|
t.string "display_name"
|
||||||
|
t.boolean "private", default: true
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "groups", ["name"], name: "index_groups_on_name", using: :btree
|
add_index "groups", ["name"], name: "index_groups_on_name", using: :btree
|
||||||
add_index "groups", ["target_id"], name: "index_groups_on_target_id", using: :btree
|
|
||||||
add_index "groups", ["user_id", "name"], name: "index_groups_on_user_id_and_name", unique: true, using: :btree
|
add_index "groups", ["user_id", "name"], name: "index_groups_on_user_id_and_name", unique: true, using: :btree
|
||||||
add_index "groups", ["user_id"], name: "index_groups_on_user_id", using: :btree
|
add_index "groups", ["user_id"], name: "index_groups_on_user_id", using: :btree
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue