Sha256: a2892960666fc02c7fa3c2ac00430557d78f07f6869835a6f853291184734aa4

Contents?: true

Size: 1.4 KB

Versions: 32

Compression:

Stored size: 1.4 KB

Contents

class Newsitem
  include Mongoid::Document
  include Mongoid::Timestamps

  belongs_to :site,    :optional => true
  belongs_to :tag,     :optional => true
  belongs_to :city,    :optional => true
  belongs_to :report,  :optional => true
  belongs_to :user_profile, class_name: 'IshModels::UserProfile', optional: true
  
  belongs_to :gallery, :optional => true
  def gallery
    self.gallery_id ? Gallery.unscoped.find( self.gallery_id ) : nil
  end

  belongs_to :video,   :optional => true

  has_one :photo

  field :name
  field :descr
  field :image_path
  field :link_path
  field :username
  field :partial_name

  field :weight,           :type => Integer, :default => 10
  field :n_upvotes,        :type => Integer, :default => 0
  field :n_downvotes,      :type => Integer, :default => 0
  field :upvoting_users,   :type => Array, :default => []
  field :downvoting_users, :type => Array, :default => []
  field :is_feature,       :type => Boolean, :default => false

  default_scope ->{ order_by({ :created_at => :desc }) }

  def self.from_params item
    n = Newsitem.new
    n.descr = item[:descr]
    n.username = item[:username]

    unless item[:report_id].blank?
      n.report = Report.find item[:report_id]
    end
    
    unless item[:gallery_id].blank?
      n.gallery = Gallery.find item[:gallery_id]
    end

    n.partial_name = item.partial_name unless item.partial_name.blank?

    return n
  end
  
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
ish_models-0.0.33.96 lib/newsitem.rb
ish_models-0.0.33.95 lib/newsitem.rb
ish_models-0.0.33.94 lib/newsitem.rb
ish_models-0.0.33.92 lib/newsitem.rb
ish_models-0.0.33.91 lib/newsitem.rb
ish_models-0.0.33.90 lib/newsitem.rb
ish_models-0.0.33.89 lib/newsitem.rb
ish_models-0.0.33.87 lib/newsitem.rb
ish_models-0.0.33.86 lib/newsitem.rb
ish_models-0.0.33.85 lib/newsitem.rb
ish_models-0.0.33.83 lib/newsitem.rb
ish_models-0.0.33.79 lib/newsitem.rb