Sha256: 0d169abdcaed8a54041d4f8094613e46f5083c367011247c715295ea3d575852

Contents?: true

Size: 839 Bytes

Versions: 5

Compression:

Stored size: 839 Bytes

Contents

# Standard Association 是标准之间的关联关系。
# association_code: REVS 修订,RFRC 引用。
class Unidom::Standard::StandardAssociating < ActiveRecord::Base

  self.table_name = 'unidom_standard_associatings'

  include Unidom::Common::Concerns::ModelExtension

  scope :source_is, ->(source) { where source_id: (source.respond_to?(:id) ? source.id : source) }
  scope :target_is, ->(target) { where target_id: (target.respond_to?(:id) ? target.id : target) }

  belongs_to :source, class_name: 'Unidom::Standard::Standard', foreign_key: :source_id
  belongs_to :target, class_name: 'Unidom::Standard::Standard', foreign_key: :target_id

  def self.associate!(source, with: target, due_to: 'REVS', at: Time.now)
    create! source_id: to_id(source), target_id: to_id(with), association_code: due_to, opened_at: at
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
unidom-standard-1.3 app/models/unidom/standard/standard_associating.rb
unidom-standard-1.2 app/models/unidom/standard/standard_associating.rb
unidom-standard-1.1 app/models/unidom/standard/standard_associating.rb
unidom-standard-1.0.1 app/models/unidom/standard/standard_associating.rb
unidom-standard-1.0 app/models/unidom/standard/standard_associating.rb