belongs_to :user
belongs_to :client_application
- scope :valid, where(:invalidated_at => nil)
+ scope :valid, -> { where(:invalidated_at => nil) }
validates_presence_of :user, :secret
belongs_to :user, :counter_cache => true
belongs_to :language, :foreign_key => 'language_code'
- has_many :comments, :class_name => "DiaryComment",
- :include => :user,
- :order => "diary_comments.id"
- has_many :visible_comments, :class_name => "DiaryComment",
- :include => :user,
- :conditions => {
- :users => { :status => ["active", "confirmed" ] },
- :visible => true
- },
- :order => "diary_comments.id"
-
- scope :visible, where(:visible => true)
+ has_many :comments, -> { order(:id).preload(:user) }, :class_name => "DiaryComment"
+ has_many :visible_comments, -> { joins(:user).where(:visible => true, :users => { :status => ["active", "confirmed"] }).order(:id) }, :class_name => "DiaryComment"
+
+ scope :visible, -> { where(:visible => true) }
validates_presence_of :title, :body
validates_length_of :title, :within => 1..255
belongs_to :changeset
- has_many :old_nodes, :order => :version
+ has_many :old_nodes, -> { order(:version) }
has_many :way_nodes
has_many :ways, :through => :way_nodes
validate :validate_position
validates_associated :changeset
- scope :visible, where(:visible => true)
- scope :invisible, where(:visible => false)
+ scope :visible, -> { where(:visible => true) }
+ scope :invisible, -> { where(:visible => false) }
# Sanity check the latitude and longitude and add an error if it's broken
def validate_position
class Note < ActiveRecord::Base
include GeoRecord
- has_many :comments, :class_name => "NoteComment",
- :foreign_key => :note_id,
- :order => :created_at,
- :conditions => { :visible => true }
+ has_many :comments, -> { where(:visible => true).order(:created_at) }, :class_name => "NoteComment", :foreign_key => :note_id
validates_presence_of :id, :on => :update
validates_uniqueness_of :id
belongs_to :client_application
belongs_to :user
- scope :authorized, where("authorized_at IS NOT NULL and invalidated_at IS NULL")
+ scope :authorized, -> { where("authorized_at IS NOT NULL and invalidated_at IS NULL") }
validates_uniqueness_of :token
validates_presence_of :client_application, :token
belongs_to :redaction
belongs_to :current_relation, :class_name => "Relation", :foreign_key => "relation_id"
- has_many :old_members, :class_name => 'OldRelationMember', :foreign_key => [:relation_id, :version], :order => :sequence_id
+ has_many :old_members, -> { order(:sequence_id) }, :class_name => 'OldRelationMember', :foreign_key => [:relation_id, :version]
has_many :old_tags, :class_name => 'OldRelationTag', :foreign_key => [:relation_id, :version]
validates_associated :changeset
belongs_to :changeset
- has_many :old_relations, :order => 'version'
+ has_many :old_relations, -> { order(:version) }
- has_many :relation_members, :order => 'sequence_id'
+ has_many :relation_members, -> { order(:sequence_id) }
has_many :relation_tags
has_many :containing_relation_members, :class_name => "RelationMember", :as => :member
validates_numericality_of :changeset_id, :version, :integer_only => true
validates_associated :changeset
- scope :visible, where(:visible => true)
- scope :invisible, where(:visible => false)
- scope :nodes, lambda { |*ids| joins(:relation_members).where(:current_relation_members => { :member_type => "Node", :member_id => ids }) }
- scope :ways, lambda { |*ids| joins(:relation_members).where(:current_relation_members => { :member_type => "Way", :member_id => ids }) }
- scope :relations, lambda { |*ids| joins(:relation_members).where(:current_relation_members => { :member_type => "Relation", :member_id => ids }) }
+ scope :visible, -> { where(:visible => true) }
+ scope :invisible, -> { where(:visible => false) }
+ scope :nodes, ->(*ids) { joins(:relation_members).where(:current_relation_members => { :member_type => "Node", :member_id => ids.flatten }) }
+ scope :ways, ->(*ids) { joins(:relation_members).where(:current_relation_members => { :member_type => "Way", :member_id => ids.flatten }) }
+ scope :relations, ->(*ids) { joins(:relation_members).where(:current_relation_members => { :member_type => "Relation", :member_id => ids.flatten }) }
TYPES = ["node", "way", "relation"]
has_many :tags, :class_name => 'Tracetag', :foreign_key => 'gpx_id', :dependent => :delete_all
has_many :points, :class_name => 'Tracepoint', :foreign_key => 'gpx_id', :dependent => :delete_all
- scope :visible, where(:visible => true)
- scope :visible_to, lambda { |u| visible.where("visibility IN ('public', 'identifiable') OR user_id = ?", u) }
- scope :public, where(:visibility => ["public", "identifiable"])
- scope :tagged, lambda { |t| joins(:tags).where(:gpx_file_tags => { :tag => t }) }
+ scope :visible, -> { where(:visible => true) }
+ scope :visible_to, ->(u) { visible.where("visibility IN ('public', 'identifiable') OR user_id = ?", u) }
+ scope :public, -> { where(:visibility => ["public", "identifiable"]) }
+ scope :tagged, ->(t) { joins(:tags).where(:gpx_file_tags => { :tag => t }) }
validates_presence_of :user_id, :name, :timestamp
validates_presence_of :description, :on => :create
class User < ActiveRecord::Base
require 'xml/libxml'
- has_many :traces, :conditions => { :visible => true }
- has_many :diary_entries, :order => 'created_at DESC'
- has_many :diary_comments, :order => 'created_at DESC'
- has_many :messages, :foreign_key => :to_user_id, :conditions => { :to_user_visible => true }, :order => 'sent_on DESC', :include => [:sender, :recipient]
- has_many :new_messages, :class_name => "Message", :foreign_key => :to_user_id, :conditions => { :to_user_visible => true, :message_read => false }, :order => 'sent_on DESC'
- has_many :sent_messages, :class_name => "Message", :foreign_key => :from_user_id, :conditions => { :from_user_visible => true }, :order => 'sent_on DESC', :include => [:sender, :recipient]
- has_many :friends, :include => :befriendee, :conditions => "users.status IN ('active', 'confirmed')"
+ has_many :traces, -> { where(:visible => true) }
+ has_many :diary_entries, -> { order(:created_at => :desc) }
+ has_many :diary_comments, -> { order(:created_at => :desc) }
+ has_many :messages, -> { where(:to_user_visible => true).order(:sent_on => :desc).preload(:sender, :recipient) }, :foreign_key => :to_user_id
+ has_many :new_messages, -> { where(:to_user_visible => true, :message_read => false).order(:sent_on => :desc) }, :class_name => "Message", :foreign_key => :to_user_id
+ has_many :sent_messages, -> { where(:from_user_visible => true).order(:sent_on => :desc).preload(:sender, :recipient) }, :class_name => "Message", :foreign_key => :from_user_id
+ has_many :friends, -> { joins(:befriendee).where(:users => { :status => ["active", "confirmed"] }) }
has_many :friend_users, :through => :friends, :source => :befriendee
has_many :tokens, :class_name => "UserToken"
has_many :preferences, :class_name => "UserPreference"
- has_many :changesets, :order => 'created_at DESC'
+ has_many :changesets, -> { order(:created_at => :desc) }
has_many :note_comments, :foreign_key => :author_id
has_many :notes, :through => :note_comments
has_many :client_applications
- has_many :oauth_tokens, :class_name => "OauthToken", :order => "authorized_at desc", :include => [:client_application]
+ has_many :oauth_tokens, -> { order(:authorized_at => :desc).preload(:client_application) }, :class_name => "OauthToken"
has_many :blocks, :class_name => "UserBlock"
has_many :blocks_created, :class_name => "UserBlock", :foreign_key => :creator_id
has_many :roles, :class_name => "UserRole"
- scope :visible, where(:status => ["pending", "active", "confirmed"])
- scope :active, where(:status => ["active", "confirmed"])
- scope :public, where(:data_public => true)
+ scope :visible, -> { where(:status => ["pending", "active", "confirmed"]) }
+ scope :active, -> { where(:status => ["active", "confirmed"]) }
+ scope :public, -> { where(:data_public => true) }
validates_presence_of :email, :display_name
validates_confirmation_of :email#, :message => ' addresses must match'
belongs_to :changeset
- has_many :old_ways, :order => 'version'
+ has_many :old_ways, -> { order(:version) }
- has_many :way_nodes, :order => 'sequence_id'
- has_many :nodes, :through => :way_nodes, :order => 'sequence_id'
+ has_many :way_nodes, -> { order(:sequence_id) }
+ has_many :nodes, -> { order("sequence_id") }, :through => :way_nodes
has_many :way_tags
validates_numericality_of :id, :on => :update, :integer_only => true
validates_associated :changeset
- scope :visible, where(:visible => true)
- scope :invisible, where(:visible => false)
+ scope :visible, -> { where(:visible => true) }
+ scope :invisible, -> { where(:visible => false) }
# Read in xml as text and return it's Way object representation
def self.from_xml(xml, create=false)
SCALE = 10000000
def self.included(base)
- base.scope :bbox, lambda { |bbox| base.where(OSM.sql_for_area(bbox)) }
+ base.scope :bbox, ->(bbox) { base.where(OSM.sql_for_area(bbox)) }
base.before_save :update_tile
end
def self.included(base)
# this is used to extend activerecord bases, as these aren't
# in scope for the module itself.
- base.scope :unredacted, base.where(:redaction_id => nil)
+ base.scope :unredacted, -> { base.where(:redaction_id => nil) }
end
def redacted?