find_each似乎与使用finder_sql的ActiveRecord关系不一致。以前有人处理过这个吗?例如:
class User < ActiveRecord::Base
has_many :games, :dependent => :destroy,
:finder_sql =>
proc {"SELECT * FROM games WHERE player_0_id = #{id} OR player_1_id = #{id}"}
end
class Game < ActiveRecord::Base
belongs_to :player_0, :class_name => "User", :foreign_key => "player_0_id", :inverse_of => :games
belongs_to :player_1, :class_name => "User", :foreign_key => "player_1_id", :inverse_of => :games
end
调用@ user.games.each可以正常工作并遍历我们关心的所有游戏。但是调用@ user.games.find_each会导致:
ActiveRecord::StatementInvalid:
SQLite3::SQLException: no such column: games.user_id: SELECT "games".* FROM "games" WHERE "games"."user_id" = 2 AND ("games"."id" >= 0) ORDER BY "games"."id" ASC LIMIT 1000