mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-13 19:54:02 +00:00
Add 'week' column to TicketPurchases
This commit is contained in:
parent
9ff3601453
commit
c2184c1c4f
3 changed files with 26 additions and 1 deletions
|
|
@ -18,6 +18,8 @@ class TicketPurchase < ActiveRecord::Base
|
|||
scope :by_conference, ->(conference) { where(conference_id: conference.id) }
|
||||
scope :by_user, ->(user) { where(user_id: user.id) }
|
||||
|
||||
after_create :set_week
|
||||
|
||||
def self.purchase(conference, user, purchases)
|
||||
errors = []
|
||||
ActiveRecord::Base.transaction do
|
||||
|
|
@ -59,3 +61,10 @@ class TicketPurchase < ActiveRecord::Base
|
|||
purchase
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_week
|
||||
self.week = created_at.strftime('%W')
|
||||
save!
|
||||
end
|
||||
|
|
|
|||
15
db/migrate/20170419132148_add_week_to_ticket_purchases.rb
Normal file
15
db/migrate/20170419132148_add_week_to_ticket_purchases.rb
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
class AddWeekToTicketPurchases < ActiveRecord::Migration
|
||||
class TmpTicketPurchase < ActiveRecord::Base
|
||||
self.table_name = 'ticket_purchases'
|
||||
end
|
||||
|
||||
def change
|
||||
add_column :ticket_purchases, :week, :integer
|
||||
|
||||
TmpTicketPurchase.reset_column_information
|
||||
TmpTicketPurchase.find_each do |purchase|
|
||||
purchase.week = purchase.created_at ? purchase.created_at.strftime('%W') : 0
|
||||
purchase.save!
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20170302145716) do
|
||||
ActiveRecord::Schema.define(version: 20170419132148) do
|
||||
|
||||
create_table "ahoy_events", force: :cascade do |t|
|
||||
t.uuid "visit_id", limit: 16
|
||||
|
|
@ -447,6 +447,7 @@ ActiveRecord::Schema.define(version: 20170302145716) do
|
|||
t.integer "quantity", default: 1
|
||||
t.integer "user_id"
|
||||
t.integer "payment_id"
|
||||
t.integer "week"
|
||||
end
|
||||
|
||||
create_table "tickets", force: :cascade do |t|
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue