app/models/series_statement.rb in enju_biblio-0.1.0.pre2 vs app/models/series_statement.rb in enju_biblio-0.1.0.pre3
- old
+ new
@@ -5,10 +5,15 @@
:title_subseries_transcription
has_many :series_has_manifestations, :dependent => :destroy
has_many :manifestations, :through => :series_has_manifestations
belongs_to :root_manifestation, :foreign_key => :root_manifestation_id, :class_name => 'Manifestation'
+ has_many :child_relationships, :foreign_key => 'parent_id', :class_name => 'SeriesStatementRelationship', :dependent => :destroy
+ has_many :parent_relationships, :foreign_key => 'child_id', :class_name => 'SeriesStatementRelationship', :dependent => :destroy
+ has_many :children, :through => :child_relationships, :source => :child
+ has_many :parents, :through => :parent_relationships, :source => :parent
+
validates_presence_of :original_title
validate :check_issn
before_save :create_root_manifestation
acts_as_list
@@ -16,22 +21,28 @@
text :title do
titles
end
text :numbering, :title_subseries, :numbering_subseries
integer :manifestation_ids, :multiple => true do
- series_has_manifestations.pluck(:manifestation_id)
+ series_has_manifestations.collect(&:manifestation_id)
end
integer :position
boolean :periodical
integer :series_statement_merge_list_ids, :multiple => true if defined?(EnjuResourceMerge)
+ integer :parent_ids, :multiple => true do
+ parents.pluck('series_statements.id')
+ end
+ integer :child_ids, :multiple => true do
+ children.pluck('series_statements.id')
+ end
end
+ attr_accessor :selected
normalize_attributes :original_title, :issn
+
paginates_per 10
- attr_accessor :selected
-
def last_issue
manifestations.where('date_of_publication IS NOT NULL').order('date_of_publication DESC').first || manifestations.order(:id).last
end
def check_issn
@@ -66,10 +77,15 @@
def manifestation_included(manifestation)
series_has_manifestations.where(:manifestation_id => manifestation.id).first
end
def titles
- [original_title, title_transcription]
+ [
+ original_title,
+ title_transcription,
+ parents.map{|parent| [parent.original_title, parent.title_transcription]},
+ children.map{|child| [child.original_title, child.title_transcription]}
+ ].flatten.compact
end
if defined?(EnjuResourceMerge)
has_many :series_statement_merges, :dependent => :destroy
has_many :series_statement_merge_lists, :through => :series_statement_merges