Adopt Rails 5 belongs_to_required_by_default

This commit is contained in:
Patrick Gansterer 2020-08-01 02:49:15 +02:00
parent 2557645f4f
commit 44a198c7bc
23 changed files with 53 additions and 38 deletions

View file

@ -76,6 +76,7 @@ class OrdersController < ApplicationController
def create
@order = Order.new(params[:order])
@order.created_by = current_user
@order.updated_by = current_user
if @order.save
flash[:notice] = I18n.t('orders.create.notice')
redirect_to @order

View file

@ -18,9 +18,9 @@ class BankTransaction < ApplicationRecord
# @return [Binary] Optional PNG image for e.g. scan of paper receipt.
belongs_to :bank_account
belongs_to :financial_link
belongs_to :supplier, foreign_key: 'iban', primary_key: 'iban'
belongs_to :user, foreign_key: 'iban', primary_key: 'iban'
belongs_to :financial_link, optional: true
belongs_to :supplier, optional: true, foreign_key: 'iban', primary_key: 'iban'
belongs_to :user, optional: true, foreign_key: 'iban', primary_key: 'iban'
validates_presence_of :date, :amount, :bank_account_id
validates_numericality_of :amount

View file

@ -1,7 +1,7 @@
class Delivery < StockEvent
belongs_to :supplier
belongs_to :invoice
belongs_to :invoice, optional: true
scope :recent, -> { order('created_at DESC').limit(10) }

View file

@ -1,12 +1,12 @@
# financial transactions are the foodcoop internal financial transactions
# only ordergroups have an account balance and are happy to transfer money
class FinancialTransaction < ApplicationRecord
belongs_to :ordergroup
belongs_to :ordergroup, optional: true
belongs_to :user
belongs_to :financial_link
belongs_to :financial_link, optional: true
belongs_to :financial_transaction_type
belongs_to :group_order
belongs_to :reverts, class_name: 'FinancialTransaction', foreign_key: 'reverts_id'
belongs_to :group_order, optional: true
belongs_to :reverts, optional: true, class_name: 'FinancialTransaction', foreign_key: 'reverts_id'
has_one :reverted_by, class_name: 'FinancialTransaction', foreign_key: 'reverts_id'
validates_presence_of :amount, :note, :user_id

View file

@ -1,6 +1,6 @@
class FinancialTransactionType < ApplicationRecord
belongs_to :financial_transaction_class
belongs_to :bank_account
belongs_to :bank_account, optional: true
has_many :financial_transactions, dependent: :restrict_with_exception
validates :name, presence: true

View file

@ -5,11 +5,11 @@ class GroupOrder < ApplicationRecord
attr_accessor :group_order_articles_attributes
belongs_to :order
belongs_to :ordergroup
belongs_to :ordergroup, optional: true
has_many :group_order_articles, :dependent => :destroy
has_many :order_articles, :through => :group_order_articles
has_one :financial_transaction
belongs_to :updated_by, :class_name => "User", :foreign_key => "updated_by_user_id"
belongs_to :updated_by, optional: true, class_name: 'User', foreign_key: 'updated_by_user_id'
validates_presence_of :order_id
validates_numericality_of :price

View file

@ -3,7 +3,7 @@ class Invoice < ApplicationRecord
belongs_to :supplier
belongs_to :created_by, :class_name => 'User', :foreign_key => 'created_by_user_id'
belongs_to :financial_link
belongs_to :financial_link, optional: true
has_many :deliveries, dependent: :nullify
has_many :orders, dependent: :nullify

View file

@ -11,8 +11,8 @@ class Order < ApplicationRecord
has_many :users_ordered, :through => :ordergroups, :source => :users
has_many :comments, -> { order('created_at') }, :class_name => "OrderComment"
has_many :stock_changes
belongs_to :invoice
belongs_to :supplier
belongs_to :invoice, optional: true
belongs_to :supplier, optional: true
belongs_to :updated_by, :class_name => 'User', :foreign_key => 'updated_by_user_id'
belongs_to :created_by, :class_name => 'User', :foreign_key => 'created_by_user_id'

View file

@ -6,7 +6,7 @@ class OrderArticle < ApplicationRecord
belongs_to :order
belongs_to :article
belongs_to :article_price
belongs_to :article_price, optional: true
has_many :group_order_articles, :dependent => :destroy
validates_presence_of :order_id, :article_id

View file

@ -1,7 +1,7 @@
class StockChange < ApplicationRecord
belongs_to :delivery, foreign_key: 'stock_event_id'
belongs_to :order
belongs_to :stock_taking, foreign_key: 'stock_event_id'
belongs_to :delivery, optional: true, foreign_key: 'stock_event_id'
belongs_to :order, optional: true
belongs_to :stock_taking, optional: true, foreign_key: 'stock_event_id'
belongs_to :stock_article
validates_presence_of :stock_article_id, :quantity

View file

@ -9,7 +9,7 @@ class Supplier < ApplicationRecord
has_many :deliveries
has_many :invoices
belongs_to :supplier_category
belongs_to :shared_supplier # for the sharedLists-App
belongs_to :shared_supplier, optional: true # for the sharedLists-App
validates :name, :presence => true, :length => { :in => 4..30 }
validates :phone, :presence => true, :length => { :in => 8..25 }

View file

@ -2,8 +2,8 @@
class Task < ApplicationRecord
has_many :assignments, :dependent => :destroy
has_many :users, :through => :assignments
belongs_to :workgroup
belongs_to :periodic_task_group
belongs_to :workgroup, optional: true
belongs_to :periodic_task_group, optional: true
belongs_to :created_by, :class_name => 'User', :foreign_key => 'created_by_user_id'
scope :non_group, -> { where(workgroup_id: nil, done: false) }