-def removefromrelation(objid,type,relation,uid,db_now)
- rver=ActiveRecord::Base.connection.insert("INSERT INTO relations (id,user_id,timestamp,visible) VALUES (#{relation},#{uid},#{db_now},1)")
-
- tagsql=<<-EOF
- INSERT INTO relation_tags (id,k,v,version)
- SELECT id,k,v,#{rver} FROM current_relation_tags
- WHERE id=#{relation}
- EOF
- ActiveRecord::Base.connection.insert(tagsql)
-
- membersql=<<-EOF
- INSERT INTO relation_members (id,member_type,member_id,member_role,version)
- SELECT id,member_type,member_id,member_role,#{rver} FROM current_relation_members
- WHERE id=#{relation}
- AND (member_id!=#{objid} OR member_type!='#{type}')
- EOF
- ActiveRecord::Base.connection.insert(membersql)
-
- ActiveRecord::Base.connection.update("UPDATE current_relations SET user_id=#{uid},timestamp=#{db_now} WHERE id=#{relation}")
- ActiveRecord::Base.connection.execute("DELETE FROM current_relation_members WHERE id=#{relation} AND member_type='#{type}' AND member_id=#{objid}")
-end
+ relways=ActiveRecord::Base.connection.select_all(sql)
+ relways.each do |a|
+ removefromrelation(objid,type,a['id'],uid,db_now)
+ end
+ end