所以.. 刚从 3.0.6 升级到 3.0.14,我的一项测试开始严重失败(太棒了!)。它指出(我认为)我的 where 子句的格式不正确,我只是一直在“逃避它”。只是想确认一下(如果有人能指出我在哪里可以找到记录此更改的文档)。
一些代码:
@fields = Field.joins(:region => :country).where(:regions => {:country_id => @country}).order(:name)
产生快乐的 SQL
"SELECT `fields`.* FROM `fields` INNER JOIN `regions` ON `regions`.`id` = `fields`.`region_id` INNER JOIN `countries` ON `countries`.`id` = `regions`.`country_id` WHERE `regions`.`country_id` = 5 ORDER BY name"
然而,这个查询......
@pools = Pool.joins(:field => {:region => :country}).where(:fields => {:regions => {:country_id => @country }},:confirmed => true).order(:leaving_date)
这会在 3.0.6 中产生好的 SQL
"SELECT `pools`.* FROM `pools` INNER JOIN `fields` ON `fields`.`id` = `pools`.`field_id` INNER JOIN `regions` ON `regions`.`id` = `fields`.`region_id` INNER JOIN `countries` ON `countries`.`id` = `regions`.`country_id` WHERE `pools`.`confirmed` = 1 AND `regions`.`country_id` = 5 ORDER BY leaving_date"
但是在 3.0.14 中,它的国家 ID 的值很糟糕(似乎是整个活动记录?)
"SELECT `pools`.* FROM `pools` INNER JOIN `fields` ON `fields`.`id` = `pools`.`field_id` INNER JOIN `regions` ON `regions`.`id` = `fields`.`region_id` INNER JOIN `countries` ON `countries`.`id` = `regions`.`country_id` WHERE `pools`.`confirmed` = 1 AND `fields`.`regions` = '--- \\n:country_id: !ruby/ActiveRecord:Country \\n attributes: \\n name: Test Country 1\\n latitude: \\\"13.456\\\"\\n created_at: 2012-06-27 10:28:46 Z\\n updated_at: 2012-06-27 10:28:46 Z\\n id: 2\\n cached_slug: test-country-1\\n longitude: \\\"46.789\\\"\\n message: \\n zoom: 4.0\\n' ORDER BY leaving_date"
只是想知道是否有人可以解释这里发生了什么。我怀疑它可能永远不会起作用..