@user.posts.where('status = ?', :unfinished).all returns []
By @user.posts
, I can see there is a post with :unfinished status.
But @user.posts.where('status = ?', :unfinished).all
returns an empty array.
I've tried to invoke @user.reload
first, but it doesn't resolve the problem.
(rdb:568) @user.posts
[#<Post id: 1, content: "hehe", user_id: 1, created_at: "2010-04-03 06:16:47", updated_at: "2010-04-03 06:16:47", status: "--- :unfinished\n">]
(rdb:568) @user.posts.where('status = ?', :unfinished).all
[]
update:
Oh, I see. Rails doesn't escape :unfinished well, it missing the closing开发者_如何转开发 '
status = '--- :unfinished\n
@user.posts.where('status = :status',{:status => 'unfinished'}).all
精彩评论