Created
September 15, 2016 12:55
-
-
Save markmcdonald51/c09b48938edcb83a37414cee9e927c19 to your computer and use it in GitHub Desktop.
a few ideas (udt)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Udt < ActiveRecord::Base | |
include AASM | |
has_paper_trail | |
belongs_to :project | |
has_one :organization, through: :project | |
has_one :workflow, dependent: :destroy | |
has_many :workflow_scripts, as: :aasm_scriptable, dependent: :destroy, class_name: 'AasmScript' | |
has_many :udt_table_fields, -> { order(position: :asc) }, dependent: :destroy | |
has_many :udt_fields, through: :udt_table_fields, source: :udt_field | |
has_many :udt_forms, dependent: :destroy | |
has_many :udt_associations, as: :udt_assoc, dependent: :destroy | |
#has_many :reciprocal_associations, class_name: 'UdtAssociation' #, source: :udt #foreign_key: 'udt_id' #'udt_assoc_id' | |
# , after_add: :reset_udt_const, after_remove: :reset_udt_const | |
has_many :udt_import_maps, dependent: :destroy | |
has_many :group_cruds, dependent: :destroy | |
has_many :label_fields, dependent: :destroy | |
has_many :label_udt_fields, through: :label_fields, source: :udt_field | |
has_one :csv_import, as: :importable | |
has_one :image, -> { where usage: 'front_page'}, | |
as: :attachable, dependent: :destroy, class_name: 'Attachment' | |
validates_presence_of :name, :project_id #, :db_table_name | |
validates_uniqueness_of :db_table_name, scope: :project | |
validates_uniqueness_of :name, scope: :project | |
# TODO: fix this!! | |
before_validation :set_project_table_name, on: :create | |
after_destroy :drop_udt | |
after_update :reset_udt_const | |
aasm do | |
state :disabled, :initial => true | |
state :active #, :before_enter => :create_or_alter_table | |
event :activate do | |
transitions :from => [:disabled], :to => :active | |
end | |
event :disable do | |
transitions :from => [:active], :to => :disabled | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment