No edit summary |
(Updated Edited template to July 12, 2025.) |
||
(7 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
===== | <message>Write the content here to display this box</message> | ||
A boolean in OCL can be both Non-nullable and Nullable. | ===== Definition ===== | ||
A boolean in OCL can be both Non-nullable and Nullable. | |||
NonNullableBoolean : Boolean | NonNullableBoolean : Boolean | ||
NullableBoolean : Boolean? | NullableBoolean : Boolean? | ||
As an attribute on a class that is saved to database, almost always use '''non-nullable'''. Why? Because otherwise it will default to null and it's easy to | As an attribute on a class that is saved to the database, almost always use '''non-nullable'''. Why? Because otherwise, it will default to null, and it's easy to handle ''False'' and ''Null'' mistakenly and incorrectly. | ||
===== Evaluating ===== | ===== Evaluating ===== | ||
Remember to evaluate booleans like this | Remember to evaluate booleans like this: | ||
'''class.BooleanAttribute''' | '''class.BooleanAttribute''' | ||
'''not class.BooleanAttribute''' | '''not class.BooleanAttribute''' | ||
Not like this: | |||
class.BooleanAttribute = True | class.BooleanAttribute = True | ||
Line 17: | Line 18: | ||
i.e. without an equal sign and True, False. | i.e. without an equal sign and True, False. | ||
===== Mistakes | ===== Mistakes We Have Seen Happen ===== | ||
class.BooleanAttribute->notEmpty | class.BooleanAttribute->notEmpty | ||
The expression will always return True | The expression will always return True because it will be converted to a list with one Boolean and that list will never be empty. | ||
See also [[Initial values and Default Database values]] for more information on adding Boolean values and evolving the database | |||
[[Category:OCL]] | [[Category:OCL]] | ||
{{Edited|July|12|2025}} |
Latest revision as of 05:46, 20 January 2025
Definition
A boolean in OCL can be both Non-nullable and Nullable.
NonNullableBoolean : Boolean
NullableBoolean : Boolean?
As an attribute on a class that is saved to the database, almost always use non-nullable. Why? Because otherwise, it will default to null, and it's easy to handle False and Null mistakenly and incorrectly.
Evaluating
Remember to evaluate booleans like this:
class.BooleanAttribute not class.BooleanAttribute
Not like this:
class.BooleanAttribute = True class.BooleanAttribute = False
i.e. without an equal sign and True, False.
Mistakes We Have Seen Happen
class.BooleanAttribute->notEmpty
The expression will always return True because it will be converted to a list with one Boolean and that list will never be empty.
See also Initial values and Default Database values for more information on adding Boolean values and evolving the database