Rails 3. Request for untruth

I have a table called sched_sessions and a boolean column called an instructor that checks if the teacher taught the class or not.

Therefore, I need to find all the records where the teacher did not teach the class. But I can’t do this: ScheduledSession.where(:instructor_performed => false)because if the cell is empty, it will not return this record. I just need all the records that are NOT true.

+3
source share
1 answer

It looks like your column instructor_performedcould be true, false, or NULL, so you need to query for false or NULL, for example:

ScheduledSession.where(instructor_performed: [false, nil])

, , . :

add_column :scheduled_session, :instructor_performed, :boolean,
  null: false, default: false

create_table :scheduled_session do |t|
  t.boolean :instructor_performed, null: false, default: false
  ...
end

:

change_column_null :scheduled_session, :instructor_performed, false, false

, , false . ( no-nulls, .)

nulls, ( tri-state), , , :

ScheduledSession.where(instructor_performed: false)

, ( ), SQL, "instructor_performed != true", , SQL = != NULL. , . SQL :

SELECT * from scheduled_sessions WHERE instructor_performed IS NULL
  OR instructor_performed = FALSE;

Rails where , , .

+18

All Articles