Note that there are some explanatory texts on larger screens.

plurals
  1. POActiveRecord gives 'no such column' SQL error for simple has_many association
    primarykey
    data
    text
    <p>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:</p> <pre><code>first_game = Game.find(:first) first_game.patches </code></pre> <p>As soon as I use the patches method, I get this:</p> <pre><code>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 `&lt;main&gt;' </code></pre> <p>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!</p> <p>Here's models/game.rb:</p> <pre><code>class Game &lt; ActiveRecord::Base has_many :patches end </code></pre> <p>Here's models/patches.rb:</p> <pre><code>class Patch &lt; ActiveRecord::Base belongs_to :game end </code></pre> <p>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!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload