Model Class
Model Class
associationInfo()— Returns a struct containing all association definitions for this model.associationNames()— Returns a list of association names defined on this model.average()— Calculates the average value for a given property.callbackInfo()— Returns a struct containing all callback definitions for this model, keyed by callback typeclassInfo()— Returns a comprehensive struct of all model metadata suitable for code generation and introspection tools.columnDataForProperty()— Returns a struct with data for the named property.columnForProperty()— Returns the column name mapped for the named model property.columnNames()— Returns a list of column names in the table mapped to this model.columns()— Returns an array of columns names for the table associated with this class.count()— Returns the number of rows that match the arguments (or all rows if no arguments are passed in).create()— Creates a new object, saves it to the database (if the validation permits it), and returns it.deleteAll()— Deletes all records that match thewhereargument.deleteByKey()— Finds the record with the supplied key and deletes it.deleteOne()— Gets an object based on conditions and deletes it.enumInfo()— Returns a struct containing all enum definitions for this model.exists()— Checks if a record exists in the table.findAll()— Returns records from the database table mapped to this model according to the arguments passed in (use thewhere</findAllKeys()— Returns all primary key values in a list.findByKey()— Fetches the requested record by primary key and returns it as an object.findEach()— Processes large result sets one record at a time without loading everything into memory.findFirst()— Fetches the first record ordered by primary key value.findInBatches()— Processes large result sets in batches without loading everything into memory at once.findLastOne()— Fetches the last record ordered by primary key value.findOne()— Fetches the first record found based on theWHEREandORDER BYclauses.getTableNamePrefix()— Returns the table name prefix set for the table.insertAll()— Inserts multiple records into the database in a single batch operation.invokeWithTransaction()— Runs the specified method within a single database transaction.isClass()— Use this method to check whether you are currently in a class-level object.isInstance()— Use this method to check whether you are currently in an instance object.maximum()— Calculates the maximum value for a given property.minimum()— Calculates the minimum value for a given property.new()— Creates a new object based on suppliedpropertiesand returns it.onMissingMethod()— This method is not designed to be called directly from your code, but provides functionality for dynamic finders such asprimaryKey()— Returns the name of the primary key for this model’s table.primaryKeys()— Alias forprimaryKey().propertyNames()— Returns a list of property names ordered by their respective column’s ordinal position in the database table.save()— Saves the object if it passes validation and callbacks.scopeInfo()— Returns a struct containing all named scope definitions for this model.sum()— Calculates the sum of values for a given property.tableName()— Returns the name of the database table that this model is mapped to.updateAll()— Updates all properties for the records that match thewhereargument.updateByKey()— Finds the object with the suppliedkeyand saves it (if validation permits it) with the suppliedpropupdateOne()— Gets an object based on the arguments used and updates it with the suppliedproperties.upsertAll()— Inserts or updates multiple records in a single batch operation (upsert).validationInfo()— Returns a struct containing all validation rules for this model, keyed by trigger (onSave,onCreate</validationTypeForProperty()— Returns the validation type for the property.withAdvisoryLock()— Executes a callback while holding a database advisory lock.