ActiveRecord::StatementInvalid SQLite3::SQLException: no such column: true:

前端 未结 3 1074
无人及你
无人及你 2020-12-31 21:20

I want to have @messages return @folder.messages where the value of column \"deleted\" is NOT equal to true. I\'m not sure why this keeps throwing a SQLException. I guess

3条回答
  •  自闭症患者
    2020-12-31 22:20

    @ms = @msgs.where("deleted != ?", true) 
    # OR
    @ms = @msgs.where(:deleted => false) 
    

    true is different for different databases. In some it is t/f value, and in some true/false, so you should or place it in quotes and be sure if it is right for your particular database, or you should exclude it out of your sql so Rails will do the job for you.

    UPD

    If deleted is NULL. First. Set deleted field as a false by default. Second, how to find it with AR:

    @ms = @msgs.where("deleted = ? OR deleted = ?", false, nil)
    # wich won't work, Thanks to @mu is too short
    @ms = @msgs.where("deleted = ? OR deleted IS NULL", false)
    

提交回复
热议问题