Does Rails have a built-in equivalent to the Django NullBoolean, accepting three values (nil, true, false)? If not, how would you recommend implementing it?
In my case I have a table of Overrides and a table of Objects. Objects can have many Overrides. Overrides are nearly identical in structure to Objects. Before reading the value of an Object, I’m pulling its Overrides, conditionally picking through them, and then applying those values on top of the Object.
Any field of an Override that is nil does not apply any changes. This system is working well for me, but I just added a boolean field to Objects, so I need to put a nullable boolean on Overrides. Django’s NullBoolean works well in this type of scenario, but I’m having trouble finding a rails equivalent.
ActiveRecord separates nullability and type in the database. Also, ActiveRecord creates columns as nullable unless you explicitly specify
:null => falsewhen you create/alter the column. So you should be able to create a standard boolean column:and then assign true/false/nil as needed: