아직 레일이있는 멍청한 녀석이지만 약간 이상하게 보이는 부분이 있습니다. 나는 thusly 히sqlite 레일이있는 부울
t.column :admin, :bool, :default => false, :null => false
는 그러나, sqlite3를 데이터베이스에 값이 't'
또는 'f'
가 될 것으로 보인다 데이터베이스에 모델에 부울 필드를 추가했습니다. 그건 괜찮아요,하지만 난 여전히 값 'f'
경우 user.admin?
false를 반환합니다 기대하고있다.
>> user = User.first
=> #<User id: 2, login: "matt", name: "", email: "[email protected]", crypt
ed_password: "c6740f820b4cbf6e3d88188719f23cd3053a54f0", salt: "5629f5ee09f51543
a7d64dd903b8d9e53aa43a24", created_at: "2009-04-26 23:08:05", updated_at: "2009-
04-26 23:10:38", remember_token: nil, remember_token_expires_at: nil, admin: "t"
>
>> user.admin?
=> true
>> user.admin = false
=> false
>> user.save
=> true
>> user = User.first
=> #<User id: 2, login: "matt", name: "", email: "[email protected]", crypt
ed_password: "c6740f820b4cbf6e3d88188719f23cd3053a54f0", salt: "5629f5ee09f51543
a7d64dd903b8d9e53aa43a24", created_at: "2009-04-26 23:08:05", updated_at: "2009-
05-06 03:32:23", remember_token: nil, remember_token_expires_at: nil, admin: "f"
>
>> user.admin?
=> true
SQLite는이 좀 이상한 문제인가, 아니면 그냥 뭔가를 받고 있지 않다 : 다음 콘솔 세션에서 볼 수 있듯이, 그것은 그렇지 않습니다?
정확한 답변을 모르겠지만 SQLite 자체가 아닌 Ruby/Rails와 관련이 있다고 생각합니다. SQLite는 실제로 부울 데이터 유형을 가지지 않으므로 (http://www.sqlite.org/datatype3.html 참조), 어떻게 든 그것을 인코딩하는 래퍼의 책임이 있습니다. 일반적으로 1이나 0이 사용되지만 레일스는 이상한 일을하고있을 것입니다. 또한, SQLite는 약형이므로 int를 varchar 열에 넣을 수 있으며 고통이 발생할 수 있습니다 (http://chriscraig.net/blog/sqlite-boolean-true-or-false/ 관련 토론 참조).) 조심하지 않으면. –