mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
Declare old belongs_to default on remaining models
It would take ages to go through all files now and assess all belongs_to associations. So I just declare the old default and then we can move on and apply the new default for the application while these classes still use the old one. All new models will then use the new default which is the goal of this excercise and we can refactor old classes when we touch them anyway.
This commit is contained in:
@@ -10,6 +10,8 @@
|
||||
# shopfront (outgoing products). But the set of shown products can be smaller
|
||||
# than all incoming products.
|
||||
class Exchange < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
acts_as_taggable
|
||||
|
||||
belongs_to :order_cycle
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ExchangeFee < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
belongs_to :exchange
|
||||
belongs_to :enterprise_fee
|
||||
end
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ExchangeVariant < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
belongs_to :exchange
|
||||
belongs_to :variant, class_name: 'Spree::Variant'
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class InventoryItem < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
belongs_to :enterprise
|
||||
belongs_to :variant, class_name: "Spree::Variant"
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Invoice < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
belongs_to :order, class_name: 'Spree::Order'
|
||||
serialize :data, Hash
|
||||
before_validation :serialize_order
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
require 'open_food_network/scope_variant_to_hub'
|
||||
|
||||
class OrderCycle < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
searchable_attributes :orders_open_at, :orders_close_at, :coordinator_id
|
||||
searchable_scopes :active, :inactive, :active_or_complete, :upcoming, :closed, :not_closed,
|
||||
:dated, :undated, :soonest_opening, :soonest_closing, :most_recently_closed
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class OrderCycleSchedule < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
belongs_to :schedule
|
||||
belongs_to :order_cycle
|
||||
end
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ProducerProperty < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
belongs_to :producer, class_name: 'Enterprise', touch: true
|
||||
belongs_to :property, class_name: 'Spree::Property'
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
# This reduces the need to keep Orders in sync with their parent Subscriptions
|
||||
|
||||
class ProxyOrder < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
belongs_to :order, class_name: 'Spree::Order'
|
||||
belongs_to :subscription
|
||||
belongs_to :order_cycle
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ReportRenderingOptions < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
belongs_to :user, class_name: "Spree::User"
|
||||
serialize :options, Hash
|
||||
end
|
||||
|
||||
@@ -4,6 +4,8 @@ module Spree
|
||||
class Address < ApplicationRecord
|
||||
include AddressDisplay
|
||||
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
searchable_attributes :firstname, :lastname, :phone, :full_name
|
||||
searchable_associations :country, :state
|
||||
|
||||
|
||||
@@ -31,6 +31,8 @@ module Spree
|
||||
class Adjustment < ApplicationRecord
|
||||
extend Spree::LocalizedNumber
|
||||
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
# Deletion of metadata is handled in the database.
|
||||
# So we don't need the option `dependent: :destroy` as long as
|
||||
# AdjustmentMetadata has no destroy logic itself.
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
module Spree
|
||||
class Asset < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
belongs_to :viewable, polymorphic: true, touch: true
|
||||
acts_as_list scope: :viewable
|
||||
end
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
module Spree
|
||||
class Calculator < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
belongs_to :calculable, polymorphic: true
|
||||
|
||||
# This method must be overriden in concrete calculator.
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
module Spree
|
||||
class CreditCard < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
belongs_to :payment_method
|
||||
belongs_to :user
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
module Spree
|
||||
class InventoryUnit < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
belongs_to :variant, -> { with_deleted }, class_name: "Spree::Variant"
|
||||
belongs_to :order, class_name: "Spree::Order"
|
||||
belongs_to :shipment, class_name: "Spree::Shipment"
|
||||
|
||||
@@ -8,6 +8,8 @@ module Spree
|
||||
include VariantUnits::VariantAndLineItemNaming
|
||||
include LineItemStockChanges
|
||||
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
searchable_attributes :price, :quantity, :order_id, :variant_id, :tax_category_id
|
||||
searchable_associations :order, :order_cycle, :variant, :product, :supplier, :tax_category
|
||||
searchable_scopes :with_tax, :without_tax
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
module Spree
|
||||
class LogEntry < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
belongs_to :source, polymorphic: true
|
||||
|
||||
# Fix for Spree #1767
|
||||
|
||||
@@ -13,6 +13,8 @@ module Spree
|
||||
include Balance
|
||||
include SetUnusedAddressFields
|
||||
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
searchable_attributes :number, :state, :shipment_state, :payment_state, :distributor_id,
|
||||
:order_cycle_id, :email, :total, :customer_id
|
||||
searchable_associations :shipping_method, :bill_address, :distributor
|
||||
|
||||
@@ -7,6 +7,8 @@ module Spree
|
||||
include Spree::Payment::Processing
|
||||
extend Spree::LocalizedNumber
|
||||
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
localize_number :amount
|
||||
|
||||
IDENTIFIER_CHARS = (('A'..'Z').to_a + ('0'..'9').to_a - %w(0 1 I O)).freeze
|
||||
|
||||
@@ -7,6 +7,8 @@ module Spree
|
||||
include CalculatedAdjustments
|
||||
include PaymentMethodDistributors
|
||||
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
acts_as_taggable
|
||||
acts_as_paranoid
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
module Spree
|
||||
class Price < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
acts_as_paranoid without_default_scope: true
|
||||
|
||||
belongs_to :variant, -> { with_deleted }, class_name: 'Spree::Variant'
|
||||
|
||||
@@ -25,6 +25,8 @@ module Spree
|
||||
class Product < ApplicationRecord
|
||||
include ProductStock
|
||||
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
acts_as_paranoid
|
||||
|
||||
searchable_attributes :supplier_id, :primary_taxon_id, :meta_keywords, :sku
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
module Spree
|
||||
class ProductProperty < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
belongs_to :product, class_name: "Spree::Product", touch: true
|
||||
belongs_to :property, class_name: 'Spree::Property'
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
module Spree
|
||||
class ReturnAuthorization < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
acts_as_paranoid
|
||||
|
||||
belongs_to :order, class_name: 'Spree::Order', inverse_of: :return_authorizations
|
||||
|
||||
@@ -4,6 +4,8 @@ require 'ostruct'
|
||||
|
||||
module Spree
|
||||
class Shipment < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
belongs_to :order, class_name: 'Spree::Order'
|
||||
belongs_to :address, class_name: 'Spree::Address'
|
||||
belongs_to :stock_location, class_name: 'Spree::StockLocation'
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
module Spree
|
||||
class ShippingMethodCategory < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
belongs_to :shipping_method, class_name: 'Spree::ShippingMethod'
|
||||
belongs_to :shipping_category, class_name: 'Spree::ShippingCategory',
|
||||
inverse_of: :shipping_method_categories
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
module Spree
|
||||
class ShippingRate < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
belongs_to :shipment, class_name: 'Spree::Shipment'
|
||||
belongs_to :shipping_method, class_name: 'Spree::ShippingMethod', inverse_of: :shipping_rates
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
module Spree
|
||||
class State < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
belongs_to :country, class_name: 'Spree::Country'
|
||||
|
||||
validates :country, :name, presence: true
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
module Spree
|
||||
class StateChange < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
belongs_to :user
|
||||
belongs_to :stateful, polymorphic: true
|
||||
before_create :assign_user
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
module Spree
|
||||
class StockItem < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
acts_as_paranoid
|
||||
|
||||
belongs_to :stock_location, class_name: 'Spree::StockLocation', inverse_of: :stock_items
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
module Spree
|
||||
class StockLocation < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
has_many :stock_items, dependent: :delete_all, inverse_of: :stock_location
|
||||
has_many :stock_movements, through: :stock_items
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
module Spree
|
||||
class StockMovement < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
belongs_to :stock_item, class_name: 'Spree::StockItem'
|
||||
belongs_to :originator, polymorphic: true
|
||||
|
||||
|
||||
@@ -14,6 +14,8 @@ end
|
||||
|
||||
module Spree
|
||||
class TaxRate < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
acts_as_paranoid
|
||||
include CalculatedAdjustments
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
module Spree
|
||||
class Taxon < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
acts_as_nested_set dependent: :destroy
|
||||
|
||||
belongs_to :taxonomy, class_name: 'Spree::Taxonomy', touch: true
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
module Spree
|
||||
class TokenizedPermission < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
belongs_to :permissable, polymorphic: true
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,6 +4,8 @@ module Spree
|
||||
class User < ApplicationRecord
|
||||
include SetUnusedAddressFields
|
||||
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
searchable_attributes :email
|
||||
|
||||
devise :database_authenticatable, :token_authenticatable, :registerable, :recoverable,
|
||||
|
||||
@@ -11,6 +11,8 @@ module Spree
|
||||
include VariantUnits::VariantAndLineItemNaming
|
||||
include VariantStock
|
||||
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
acts_as_paranoid
|
||||
|
||||
searchable_attributes :sku, :display_as, :display_name
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
module Spree
|
||||
class ZoneMember < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
belongs_to :zone, class_name: 'Spree::Zone', counter_cache: true, inverse_of: :zone_members
|
||||
belongs_to :zoneable, polymorphic: true
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class StripeAccount < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
belongs_to :enterprise
|
||||
validates :stripe_user_id, :stripe_publishable_key, presence: true
|
||||
validates :enterprise_id, uniqueness: true
|
||||
|
||||
@@ -6,6 +6,8 @@ class Subscription < ApplicationRecord
|
||||
ALLOWED_PAYMENT_METHOD_TYPES = ["Spree::PaymentMethod::Check",
|
||||
"Spree::Gateway::StripeSCA"].freeze
|
||||
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
searchable_attributes :shop_id, :canceled_at, :paused_at
|
||||
searchable_associations :shop
|
||||
searchable_scopes :active, :not_ended, :not_paused, :not_canceled
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class SubscriptionLineItem < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
belongs_to :subscription, inverse_of: :subscription_line_items
|
||||
belongs_to :variant, -> { with_deleted }, class_name: 'Spree::Variant'
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class TagRule < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
belongs_to :enterprise
|
||||
|
||||
preference :customer_tags, :string, default: ""
|
||||
|
||||
@@ -6,6 +6,8 @@ class VariantOverride < ApplicationRecord
|
||||
extend Spree::LocalizedNumber
|
||||
include StockSettingsOverrideValidation
|
||||
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
acts_as_taggable
|
||||
|
||||
belongs_to :hub, class_name: 'Enterprise'
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
# frozen_string_literal: false
|
||||
|
||||
class Voucher < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
acts_as_paranoid
|
||||
|
||||
belongs_to :enterprise, optional: false
|
||||
|
||||
Reference in New Issue
Block a user