2010-12-20 7 views
0

'국가'와 '공항'이라는 두 개의 테이블이 있습니다. 적어도 하나의 공항을 가진 모든 국가를 '활동적'으로 설정하고 싶습니다. 이것은 작동하지 않습니다 : 내가 알고있는 것처럼 내가 나라 코드의리스트를 필요로 할 때레일스 활성 레코드 : 레코드 목록 업데이트

def self.activate_by_airports 
    update_all('active = 1', ['country_code IN (?)', Airport.select('DISTINCT(country_code)').where(:active => 1)]) 
    end 

는 Airport.select (...)는 공항 개체의 목록을 반환합니다.

이 경우 올바른 구문은 무엇입니까?

+0

I는지도 기능을 이용하여 해결 : Airport.select를 (' DISTINCT (country_code) '). 여기서 (: active => 1) .map {| 공항 | airport.country_code} – krn

답변

2

사용 Airport.select('DISTINCT(country_code)').where(:active => 1).toArray 또는 Airport.select ('DISTINCT (COUNTRY_CODE)') 여기서,. (: 활성 => 1) .ALL - 레일 (3) 만

관련 문제