1
0
This repository has been archived on 2023-12-07. You can view files and clone it, but cannot push or open issues or pull requests.
body_tracking/app/models/column_view.rb
2019-12-21 18:01:46 +01:00

20 lines
615 B
Ruby

class ColumnView < ActiveRecord::Base
enum domain: Quantity.domains
belongs_to :project, required: true
has_and_belongs_to_many :quantities, -> { order "lft" }
validates :name, presence: true, uniqueness: {scope: :domain}
validates :domain, inclusion: {in: domains.keys}
# TODO: enforce column_view - quantity 'domain' identity
def toggle_column!(q)
column = self.quantities.find(q.id)
self.quantities.destroy(column)
rescue ActiveRecord::RecordNotFound
# Cannot 'create' association, as ColumnView (parent) may not be saved yet
self.quantities.append(q)
self.save!
end
end