app/models/popolo/organization.rb in popolo-0.0.2 vs app/models/popolo/organization.rb in popolo-0.0.3
- old
+ new
@@ -1,32 +1,53 @@
module Popolo
# A group with a common purpose or reason for existence that goes beyond the
- # set of people belonging to it, e.g. a political structure.
+ # set of people belonging to it.
class Organization
include Mongoid::Document
+ include Mongoid::Timestamps
include Mongoid::Tree
- include Popolo::Sluggable
- index({slug: 1, parent_id: 1}, unique: true)
+ store_in Popolo.storage_options_per_class.fetch(:Organization, Popolo.storage_options)
- # An area related to the organization, e.g. a region or country.
+ # The geographic area to which the organization is related.
belongs_to :area, index: true, class_name: 'Popolo::Area'
# The relationships to which the organization is a party.
- has_many :memberships, class_name: 'Popolo::Membership', dependent: :destroy
- # The posts within the organization.
+ has_many :memberships, class_name: 'Popolo::Membership', dependent: :destroy, inverse_of: :organization
+ # The organization in which the motion is proposed.
+ has_many :motions, class_name: 'Popolo::Motion', dependent: :destroy
+ # Posts within the organization.
has_many :posts, class_name: 'Popolo::Post', dependent: :destroy
- # The organization's alternate or former names.
+ # The organization whose members are voting.
+ has_many :vote_events, class_name: 'Popolo::VoteEvent', dependent: :destroy
+ # The organization that is voting.
+ has_many :votes, as: :voter, class_name: 'Popolo::Vote'
+ # Alternate or former names.
embeds_many :other_names, as: :nameable, class_name: 'Popolo::OtherName'
- # The organization's issued identifiers.
- embeds_many :identifiers, class_name: 'Popolo::Identifier'
+ # Issued identifiers.
+ embeds_many :identifiers, as: :identifiable, class_name: 'Popolo::Identifier'
+ # Means of contacting the organization.
+ embeds_many :contact_details, as: :contactable, class_name: 'Popolo::ContactDetail'
+ # URLs to documents about the organization.
+ embeds_many :links, as: :linkable, class_name: 'Popolo::Link'
+ # URLs to documents from which the organization is derived.
+ embeds_many :sources, as: :linkable, class_name: 'Popolo::Link'
- # The organization's category.
+ # A primary name, e.g. a legally recognized name.
+ field :name, type: String
+ # An organization category, e.g. committee.
field :classification, type: String
- # The organization's date of founding in ISO 8601:2004 format.
- field :founding_date, type: String
- # The organization's date of dissolution in ISO 8601:2004 format.
- field :dissolution_date, type: String
+ # A date of founding.
+ field :founding_date, type: DateString
+ # A date of dissolution.
+ field :dissolution_date, type: DateString
+ # A URL of an image.
+ field :image, type: String
- validates_format_of :founding_date, with: /\A\d{4}(-\d{2}){0,2}\z/, allow_blank: true
- validates_format_of :dissolution_date, with: /\A\d{4}(-\d{2}){0,2}\z/, allow_blank: true
+ validates_format_of :founding_date, with: DATE_STRING_FORMAT, allow_blank: true
+ validates_format_of :dissolution_date, with: DATE_STRING_FORMAT, allow_blank: true
+ # @note Add URL validation to match JSON Schema?
+
+ def to_s
+ name
+ end
end
end