Skip to content

Commit 0d8c06b

Browse files
authored
Add owner association to charge, subscription, and payment method models (#1186)
1 parent e6697d2 commit 0d8c06b

File tree

3 files changed

+3
-0
lines changed

3 files changed

+3
-0
lines changed

app/models/pay/charge.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ class Charge < Pay::ApplicationRecord
33
# Associations
44
belongs_to :customer
55
belongs_to :subscription, optional: true
6+
has_one :owner, through: :customer
67

78
# Scopes
89
scope :sorted, -> { order(created_at: :desc) }

app/models/pay/payment_method.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module Pay
22
class PaymentMethod < Pay::ApplicationRecord
33
belongs_to :customer
4+
has_one :owner, through: :customer
45

56
store_accessor :data, :brand # Visa, Mastercard, Discover, PayPal
67
store_accessor :data, :last4

app/models/pay/subscription.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class Subscription < Pay::ApplicationRecord
66
belongs_to :customer
77
belongs_to :payment_method, optional: true, primary_key: :processor_id
88
has_many :charges
9+
has_one :owner, through: :customer
910

1011
# Scopes
1112
scope :for_name, ->(name) { where(name: name) }

0 commit comments

Comments
 (0)