Class: LineDiscount
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- LineDiscount
- Defined in:
- app/models/line_discount.rb
Overview
== Schema Information
Table name: line_discounts
Database name: primary
id :integer not null, primary key
amount :decimal(10, 2) default(0.0), not null
created_at :datetime
updated_at :datetime
coupon_id :integer
creator_id :integer
discount_id :integer not null
line_item_id :integer
updater_id :integer
Indexes
index_line_discounts_uniqueness (line_item_id,discount_id) UNIQUE
line_discounts_coupon_id_idx (coupon_id)
line_discounts_discount_id_idx (discount_id)
Foreign Keys
line_discounts_coupon_id_fkey (coupon_id => coupons.id)
line_discounts_discount_id_fkey (discount_id => discounts.id) ON DELETE => cascade
line_discounts_line_item_id_fk (line_item_id => line_items.id) ON DELETE => cascade
Instance Attribute Summary collapse
- #amount ⇒ Object readonly
- #coupon_id ⇒ Object readonly
Belongs to collapse
Delegated Instance Attributes collapse
-
#tax_class ⇒ Object
Alias for Line_item#tax_class.
Class Method Summary collapse
-
.auto_applied ⇒ ActiveRecord::Relation<LineDiscount>
A relation of LineDiscounts that are auto applied.
-
.manually_applied ⇒ ActiveRecord::Relation<LineDiscount>
A relation of LineDiscounts that are manually applied.
-
.sorted ⇒ ActiveRecord::Relation<LineDiscount>
A relation of LineDiscounts that are sorted.
-
.visible ⇒ ActiveRecord::Relation<LineDiscount>
A relation of LineDiscounts that are visible.
Instance Method Summary collapse
Methods inherited from ApplicationRecord
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
Methods included from Models::EventPublishable
Instance Attribute Details
#amount ⇒ Object (readonly)
33 |
# File 'app/models/line_discount.rb', line 33 validates :amount, presence: true, numericality: true |
#coupon_id ⇒ Object (readonly)
36 |
# File 'app/models/line_discount.rb', line 36 validates :coupon_id, uniqueness: { scope: :line_item_id } |
Class Method Details
.auto_applied ⇒ ActiveRecord::Relation<LineDiscount>
A relation of LineDiscounts that are auto applied. Active Record Scope
40 |
# File 'app/models/line_discount.rb', line 40 scope :auto_applied, -> { joins(:coupon).where(Coupon[:auto_apply].eq(true)) } |
.manually_applied ⇒ ActiveRecord::Relation<LineDiscount>
A relation of LineDiscounts that are manually applied. Active Record Scope
39 |
# File 'app/models/line_discount.rb', line 39 scope :manually_applied, -> { joins(:coupon).where(Coupon[:auto_apply].not_eq(true)) } |
.sorted ⇒ ActiveRecord::Relation<LineDiscount>
A relation of LineDiscounts that are sorted. Active Record Scope
41 |
# File 'app/models/line_discount.rb', line 41 scope :sorted, -> { joins(:coupon).merge(Coupon.sorted) } |
.visible ⇒ ActiveRecord::Relation<LineDiscount>
A relation of LineDiscounts that are visible. Active Record Scope
38 |
# File 'app/models/line_discount.rb', line 38 scope :visible, -> { where(LineDiscount[:amount].lt(0)) } |
Instance Method Details
#discount ⇒ Discount
29 |
# File 'app/models/line_discount.rb', line 29 belongs_to :discount, autosave: false |
#invisible? ⇒ Boolean
45 46 47 |
# File 'app/models/line_discount.rb', line 45 def invisible? amount == 0 end |
#line_item ⇒ LineItem
Validations:
31 |
# File 'app/models/line_discount.rb', line 31 belongs_to :line_item |
#tax_class ⇒ Object
Alias for Line_item#tax_class
43 |
# File 'app/models/line_discount.rb', line 43 delegate :tax_class, to: :line_item |