Newer
Older
dmpopidor / app / models / version.rb
@Marta Ribeiro Marta Ribeiro on 3 Jun 2016 756 bytes DMPonline4 - RAILS 4.0 (#4)
class Version < ActiveRecord::Base
  
  #associations between tables
  belongs_to :phase
  
  has_many :sections, :dependent => :destroy
  has_many :questions, :through => :sections, :dependent => :destroy
  has_many :plans
  
  #Link the data
  accepts_nested_attributes_for :phase
  accepts_nested_attributes_for :sections,  :allow_destroy => true 
  
  attr_accessible :description, :number, :published, :title, :phase_id, :as => [:default, :admin]
  
  def to_s
  	"#{title}"
  end
  
  
  
  def global_sections
  	sections.where("organisation_id = ? ", phase.dmptemplate.organisation_id).load
  end
  
  amoeba do
    include_field :sections
    include_field :questions
    set :published => 'false'
    prepend :title => "Copy of " 
  end
 
 	
end