Sha256: b8d6d41733ed02f234c7b9eb6138a640aff1fd097f511571024c0256219b45ee
Contents?: true
Size: 1.13 KB
Versions: 1
Compression:
Stored size: 1.13 KB
Contents
module Jobshop class Order < ApplicationRecord self.primary_keys = [ :organization_id, :order_id ] after_create do self.class.connection.clear_query_cache @attributes = self.class.unscoped { self.class.find_by!(organization: organization, number: number) }.instance_variable_get(:@attributes) @new_record = false self end belongs_to :organization, inverse_of: :orders belongs_to :created_by, class_name: "Jobshop::User", foreign_key: [ :organization_id, :created_by_id ] belongs_to :company, inverse_of: :orders, foreign_key: [ :organization_id, :company_id ] has_many :order_lines, inverse_of: :order, foreign_key: [ :organization_id, :order_id ] around_save :notify_on_save def add_listener(listener) (@listeners ||= []) << listener end def notify_listeners(event_name, *args) @listeners && @listeners.each do |listener| if listener.respond_to?(event_name) listener.public_send(event_name, self, *args) end end end def notify_on_save yield notify_listeners(:on_save) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
jobshop-0.0.157 | app/models/jobshop/order.rb |