2010-12-20 68 views
0

我有两个表:'国家'和'机场'。我想把所有拥有至少一个机场的国家定为“积极”的。这不起作用:Rails活动记录:更新记录列表

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

据我了解,Airport.select(...)返回机场对象的列表,当我需要的国家代码列表。

在这种情况下,正确的语法是什么?

+0

我解决它通过使用映射函数:Airport.select(” DISTINCT(country_code)')。where(:active => 1).map {| airport | airport.country_code} – krn 2010-12-20 13:31:27

回答

2

使用Airport.select('DISTINCT(country_code)').where(:active => 1).toArray或Airport.select( 'DISTINCT(COUNTRY_CODE)')的位置。(:活性=> 1)。所有 - Rails 3中仅