Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Type casting

Dynamoid supports type casting and tries to do it in the most convenient way. Values for all fields (except custom type) are coerced to declared field types.

Some obvious rules are used, e.g.:

for boolean field:

document.boolean_field = 'off'
# => false
document.boolean_field = 'false'
# => false
document.boolean_field = 'some string'
# => true

or for integer field:

document.integer_field = 42.3
# => 42
document.integer_field = '42.3'
# => 42
document.integer_field = true
# => 1

If time zone isn’t specified for datetime value - application time zone is used.

To access field value before type casting following method could be used: attributes_before_type_cast and read_attribute_before_type_cast.

There is <name>_before_type_cast method for every field in a model as well.