开发者

@user.posts.where('status = ?', :unfinished).all returns []

开发者 https://www.devze.com 2022-12-25 06:47 出处:网络
By @user.posts, I can see there is a post with :unfinished status. But @user.posts.where(\'status = ?\', :unfinished).all returns an empty array.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号