forked from rails/rails
-
Notifications
You must be signed in to change notification settings - Fork 7
/
order.rb
55 lines (42 loc) · 1.38 KB
/
order.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# frozen_string_literal: true
module Cpk
class Order < ActiveRecord::Base
self.table_name = :cpk_orders
# explicit definition is to allow schema definition to be simplified
# to be shared between different databases
self.primary_key = [:shop_id, :id]
alias_attribute :id_value, :id
has_many :order_agreements
has_many :books, foreign_key: [:shop_id, :order_id]
has_one :book, foreign_key: [:shop_id, :order_id]
has_many :order_tags
has_many :tags, through: :order_tags
end
class BrokenOrder < Order
self.primary_key = [:shop_id, :status]
has_many :books
has_one :book
end
class OrderWithSpecialPrimaryKey < Order
self.primary_key = [:shop_id, :status]
has_many :books, foreign_key: [:shop_id, :status]
has_one :book, foreign_key: [:shop_id, :status]
end
class BrokenOrderWithNonCpkBooks < Order
self.primary_key = [:shop_id, :status]
has_many :books, class_name: "Cpk::NonCpkBook"
has_one :book, class_name: "Cpk::NonCpkBook"
end
class NonCpkOrder < Order
self.primary_key = :id
end
class OrderWithPrimaryKeyAssociatedBook < Order
has_one :book, foreign_key: :order_id
end
class OrderWithNullifiedBook < Order
has_one :book, foreign_key: [:shop_id, :order_id], dependent: :nullify
end
class OrderWithSingularBookChapters < Order
has_many :chapters, through: :book
end
end