samedi 12 mars 2016

Model save method causes exception "no such column" with column name blank

I retrieve a Post instance using find_by_id, set score on it, and call save. What I see is a really strange error where the SQL is missing the field in WHERE clause. Here's my rails console output:

me> rails c
Loading development environment (Rails 3.2.22.2)
2.1.5 :001 > post = Post.find_by_id 123456
  Post Load (0.1ms)  SELECT "posts".* FROM "posts" WHERE "posts"."id" = 123456 LIMIT 1
 => #<Post id: 123456, url: "http://www.example.com", title: "Test Title", score: nil>
2.1.5 :002 > post.score = 1
 => 1
2.1.5 :003 > post.save
   (0.1ms)  begin transaction
   (0.2ms)  UPDATE "posts" SET "score" = 1 WHERE "posts"."" = 123456
   (0.0ms)  rollback transaction
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: posts.: UPDATE "posts" SET "score" = 1 WHERE "posts"."" = 123456

Aucun commentaire:

Enregistrer un commentaire