This is driving me insane! This code used to work fine, but as of a few weeks ago it stopped working, and I can't work out why. Basically a Game has many Patches. The error occurs in my PatchesController, but its reproducible in the rails console like this:
first_game = Game.find(:first)
first_game.patches
As soon as I use the patches method, I get this:
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: patches.game_true: SELECT * FROM "patches" WHERE ("patches".game_true = 1)
from /project_root/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:221:in `rescue in log'
from /project_root/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:204:in `log'
from /project_root/vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb:172:in `block in execute'
from /project_root/vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb:417:in `catch_schema_changes'
from /project_root/vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb:172:in `execute'
from /project_root/vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb:320:in `select'
from /project_root/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `select_all'
from /project_root/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:62:in `select_all_with_query_cache'
from /project_root/vendor/rails/activerecord/lib/active_record/base.rb:664:in `find_by_sql'
from /project_root/vendor/rails/activerecord/lib/active_record/base.rb:1578:in `find_every'
from /project_root/vendor/rails/activerecord/lib/active_record/base.rb:618:in `find'
from /project_root/vendor/rails/activerecord/lib/active_record/associations/association_collection.rb:60:in `find'
from /project_root/vendor/rails/activerecord/lib/active_record/associations/association_collection.rb:400:in `find_target'
from /project_root/vendor/rails/activerecord/lib/active_record/associations/association_collection.rb:354:in `load_target'
from /project_root/vendor/rails/activerecord/lib/active_record/associations/association_proxy.rb:140:in `inspect'
from /usr/local/bin/irb:12:in `<main>'
Now that SQL should really say 'WHERE patches.game_id = 1', unless I'm going mad. I have no idea why it's generating that SQL!
Here's models/game.rb:
class Game < ActiveRecord::Base
has_many :patches
end
Here's models/patches.rb:
class Patch < ActiveRecord::Base
belongs_to :game
end
And the patches table has 'game_id' in the table, and 3 entries, all for the first game. If I get one of the Patches and go my_patch.game, it returns the Game object it belongs to, with no problems. Any help would be greatly appreciated!