scinote-web/app/models/repository_list_value.rb

22 lines
667 B
Ruby
Raw Normal View History

class RepositoryListValue < ApplicationRecord
2018-02-09 21:11:56 +08:00
belongs_to :selected_item,
foreign_key: :selected_item_id,
class_name: 'RepositoryListItem',
optional: true
belongs_to :created_by,
foreign_key: :created_by_id,
2018-02-09 21:11:56 +08:00
class_name: 'User'
belongs_to :last_modified_by,
foreign_key: :last_modified_by_id,
2018-02-09 21:11:56 +08:00
class_name: 'User'
has_one :repository_cell, as: :value, dependent: :destroy, inverse_of: :value
accepts_nested_attributes_for :repository_cell
validates :repository_cell, presence: true
def formatted
2018-02-09 21:11:56 +08:00
return '' unless selected_item
selected_item.name
end
end