@classmethod<EOL><INDENT>def ensureExists(cls, values, defaults=None, **context):<DEDENT>
<EOL>if not values:<EOL><INDENT>return cls()<EOL><DEDENT>q = orb.Query()<EOL>for key, value in values.items():<EOL><INDENT>column = cls.schema().column(key)<EOL>if not column:<EOL><INDENT>raise orb.errors.ColumnNotFound(schema=cls.schema(), column=key)<EOL><DEDENT>elif column.testFlag(column.Flags.Virtual):<EOL><INDENT>continue<EOL><DEDENT>if (isinstance(column, orb.AbstractStringColumn) and<EOL>not column.testFlag(column.Flags.CaseSensitive) and<EOL>not column.testFlag(column.Flags.I18n) and<EOL>isinstance(value, (str, unicode))):<EOL><INDENT>q &= orb.Query(key).lower() == value.lower()<EOL><DEDENT>else:<EOL><INDENT>q &= orb.Query(key) == value<EOL><DEDENT><DEDENT>record = cls.select(where=q).first()<EOL>if record is None:<EOL><INDENT>record = cls(context=orb.Context(**context))<EOL>record.update(values)<EOL>record.update(defaults or {})<EOL>record.save()<EOL><DEDENT>return record<EOL>
Defines a new record for the given class based on the
inputted set of keywords.  If a record already exists for
the query, the first found record is returned, otherwise
a new record is created and returned.

:param      values | <dict>