[issue #64] Added own_projects counters to User & Group
This commit is contained in:
parent
b04a9e0176
commit
1498e937f6
|
@ -16,7 +16,7 @@ class Group < ActiveRecord::Base
|
|||
validates :uname, :presence => true, :uniqueness => {:case_sensitive => false}, :format => { :with => /^[a-z0-9_]+$/ }
|
||||
validate { errors.add(:uname, :taken) if User.where('uname LIKE ?', uname).present? }
|
||||
|
||||
attr_readonly :uname
|
||||
attr_readonly :uname, :own_projects_count
|
||||
|
||||
delegate :ssh_key, :to => :owner
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ class Project < ActiveRecord::Base
|
|||
VISIBILITIES = ['open', 'hidden']
|
||||
|
||||
belongs_to :category, :counter_cache => true
|
||||
belongs_to :owner, :polymorphic => true
|
||||
belongs_to :owner, :polymorphic => true, :counter_cache => :own_projects_count
|
||||
|
||||
has_many :issues, :dependent => :destroy
|
||||
has_many :build_lists, :dependent => :destroy
|
||||
|
|
|
@ -28,7 +28,7 @@ class User < ActiveRecord::Base
|
|||
validates :role, :inclusion => {:in => ROLES}, :allow_blank => true
|
||||
|
||||
attr_accessible :email, :password, :password_confirmation, :remember_me, :login, :name, :ssh_key, :uname
|
||||
attr_readonly :uname
|
||||
attr_readonly :uname, :own_projects_count
|
||||
attr_accessor :login
|
||||
|
||||
def admin?
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
class AddProjectsCountToUsers < ActiveRecord::Migration
|
||||
def self.up
|
||||
add_column :users, :own_projects_count, :integer, :default => 0, :null => false
|
||||
|
||||
User.reset_column_information
|
||||
User.all.each do |user|
|
||||
User.reset_counters(user.id, :own_projects)
|
||||
end
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_column :users, :own_projects_count
|
||||
end
|
||||
end
|
|
@ -0,0 +1,14 @@
|
|||
class AddProjectsCountToGroups < ActiveRecord::Migration
|
||||
def self.up
|
||||
add_column :groups, :own_projects_count, :integer, :default => 0, :null => false
|
||||
|
||||
Group.reset_column_information
|
||||
Group.all.each do |group|
|
||||
Group.reset_counters(group.id, :own_projects)
|
||||
end
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_column :groups, :projects_count
|
||||
end
|
||||
end
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20111228182425) do
|
||||
ActiveRecord::Schema.define(:version => 20120126214447) do
|
||||
|
||||
create_table "arches", :force => true do |t|
|
||||
t.string "name", :null => false
|
||||
|
@ -150,6 +150,7 @@ ActiveRecord::Schema.define(:version => 20111228182425) do
|
|||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.string "uname"
|
||||
t.integer "own_projects_count", :default => 0, :null => false
|
||||
end
|
||||
|
||||
create_table "issues", :force => true do |t|
|
||||
|
@ -294,6 +295,7 @@ ActiveRecord::Schema.define(:version => 20111228182425) do
|
|||
t.text "ssh_key"
|
||||
t.string "uname"
|
||||
t.string "role"
|
||||
t.integer "own_projects_count", :default => 0, :null => false
|
||||
end
|
||||
|
||||
add_index "users", ["email"], :name => "index_users_on_email", :unique => true
|
||||
|
|
Loading…
Reference in New Issue