Update ActiveRecord queries to use arel
This commit is contained in:
parent
a543e731c0
commit
226c41be69
20 changed files with 110 additions and 185 deletions
|
@ -1,15 +1,5 @@
|
|||
class Acl < ActiveRecord::Base
|
||||
def self.find_by_address(address, options)
|
||||
self.with_scope(:find => {:conditions => ["#{inet_aton} & netmask = address", address]}) do
|
||||
return self.find(:first, options)
|
||||
end
|
||||
end
|
||||
|
||||
def self.find_all_by_address(address, options)
|
||||
self.with_scope(:find => {:conditions => ["#{inet_aton} & netmask = address", address]}) do
|
||||
return self.find(:all, options)
|
||||
end
|
||||
end
|
||||
scope :address, lambda { |address| where("#{inet_aton} & netmask = address", address) }
|
||||
|
||||
private
|
||||
|
||||
|
|
|
@ -30,6 +30,9 @@ class Node < ActiveRecord::Base
|
|||
validate :validate_position
|
||||
validates_associated :changeset
|
||||
|
||||
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
|
||||
errors.add_to_base("Node is not in the world") unless in_world?
|
||||
|
|
|
@ -23,6 +23,12 @@ class Relation < ActiveRecord::Base
|
|||
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 }) }
|
||||
|
||||
TYPES = ["node", "way", "relation"]
|
||||
|
||||
def self.from_xml(xml, create=false)
|
||||
|
@ -148,36 +154,6 @@ class Relation < ActiveRecord::Base
|
|||
return el1
|
||||
end
|
||||
|
||||
def self.find_for_nodes(ids, options = {})
|
||||
if ids.empty?
|
||||
return []
|
||||
else
|
||||
self.with_scope(:find => { :joins => "INNER JOIN current_relation_members AS crm ON crm.id = current_relations.id", :conditions => "crm.member_type = 'Node' AND crm.member_id IN (#{ids.join(',')})" }) do
|
||||
return self.find(:all, options)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.find_for_ways(ids, options = {})
|
||||
if ids.empty?
|
||||
return []
|
||||
else
|
||||
self.with_scope(:find => { :joins => "INNER JOIN current_relation_members AS crm ON crm.id = current_relations.id", :conditions => "crm.member_type = 'Way' AND crm.member_id IN (#{ids.join(',')})" }) do
|
||||
return self.find(:all, options)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.find_for_relations(ids, options = {})
|
||||
if ids.empty?
|
||||
return []
|
||||
else
|
||||
self.with_scope(:find => { :joins => "INNER JOIN current_relation_members AS crm ON crm.id = current_relations.id", :conditions => "crm.member_type = 'Relation' AND crm.member_id IN (#{ids.join(',')})" }) do
|
||||
return self.find(:all, options)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# FIXME is this really needed?
|
||||
def members
|
||||
unless @members
|
||||
|
|
|
@ -25,6 +25,9 @@ class Way < ActiveRecord::Base
|
|||
validates_numericality_of :id, :on => :update, :integer_only => true
|
||||
validates_associated :changeset
|
||||
|
||||
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)
|
||||
begin
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue