Use association names with :joins instead of writing the SQL for the

join by hand.
This commit is contained in:
Tom Hughes 2009-04-30 23:45:55 +00:00
parent 264b92bd9f
commit 329b6faf91
3 changed files with 5 additions and 4 deletions

View file

@ -242,7 +242,8 @@ class Relation < ActiveRecord::Base
Relation.transaction do
check_consistency(self, new_relation, user)
# This will check to see if this relation is used by another relation
rel = RelationMember.find(:first, :joins => "INNER JOIN current_relations ON current_relations.id=current_relation_members.id", :conditions => [ "visible = ? AND member_type='Relation' and member_id=? ", true, self.id ])
rel = RelationMember.find(:first, :joins => :relation,
:conditions => [ "visible = ? AND member_type='Relation' and member_id=? ", true, self.id ])
raise OSM::APIPreconditionFailedError.new("The relation #{new_relation.id} is used in relation #{rel.relation.id}.") unless rel.nil?
self.changeset_id = new_relation.changeset_id