X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/5f8ab9e9244550b20b8d3bd97b3567df7020d06d..40414cf324309d13d207f9339b7f40ce05a9fa2a:/app/models/relation.rb diff --git a/app/models/relation.rb b/app/models/relation.rb index eb3b06a13..bb8f2d003 100644 --- a/app/models/relation.rb +++ b/app/models/relation.rb @@ -3,7 +3,7 @@ class Relation < ActiveRecord::Base set_table_name 'current_relations' - belongs_to :user + belongs_to :changeset has_many :old_relations, :foreign_key => 'id', :order => 'version' @@ -112,6 +112,36 @@ 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 ON current_relation_members.id = current_relations.id", :conditions => "current_relation_members.member_type = 'node' AND current_relation_members.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 ON current_relation_members.id = current_relations.id", :conditions => "current_relation_members.member_type = 'way' AND current_relation_members.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 ON current_relation_members.id = current_relations.id", :conditions => "current_relation_members.member_type = 'relation' AND current_relation_members.member_id IN (#{ids.join(',')})" }) do + return self.find(:all, options) + end + end + end + # FIXME is this really needed? def members unless @members