Add orders_count and ordering on overview
This commit is contained in:
parent
f6a37a80cf
commit
744f8090ba
4 changed files with 9 additions and 3 deletions
|
@ -27,7 +27,7 @@ class OrdersController < ApplicationController
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@users_by_name = User.all.order(:name)
|
@users_by_name = User.all.order(:name)
|
||||||
@users_by_order = User.all
|
@users_by_order = User.all.order(:orders_count).reverse_order
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
class Order < ActiveRecord::Base
|
class Order < ActiveRecord::Base
|
||||||
after_initialize { self.total_price = 0 }
|
after_initialize { self.total_price = 0 }
|
||||||
belongs_to :user
|
belongs_to :user, counter_cache: true
|
||||||
|
|
||||||
has_many :order_products
|
has_many :order_products
|
||||||
has_many :products, { through: :order_products} do
|
has_many :products, { through: :order_products} do
|
||||||
|
|
5
db/migrate/20141210090544_add_orders_count_to_users.rb
Normal file
5
db/migrate/20141210090544_add_orders_count_to_users.rb
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
class AddOrdersCountToUsers < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :users, :orders_count, :integer, default: 0
|
||||||
|
end
|
||||||
|
end
|
|
@ -11,7 +11,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20141209204351) do
|
ActiveRecord::Schema.define(version: 20141210090544) do
|
||||||
|
|
||||||
create_table "order_products", force: true do |t|
|
create_table "order_products", force: true do |t|
|
||||||
t.integer "order_id"
|
t.integer "order_id"
|
||||||
|
@ -60,6 +60,7 @@ ActiveRecord::Schema.define(version: 20141209204351) do
|
||||||
t.string "avatar_content_type"
|
t.string "avatar_content_type"
|
||||||
t.integer "avatar_file_size"
|
t.integer "avatar_file_size"
|
||||||
t.datetime "avatar_updated_at"
|
t.datetime "avatar_updated_at"
|
||||||
|
t.integer "orders_count", default: 0
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue