Model Configuration
Model Configuration
accessibleProperties()— Use this method inside your model’s config() function to whitelist which properties can be set via mass assignment operaafterCreate()— Registers one or more callback methods that are automatically executed after a new object is created (i.e., after callinafterDelete()— Registers one or more callback methods that should be executed after an object is deleted from the database. This hook aafterFind()— Registers one or more callback methods that should be executed after an existing object has been initialized, typicallyafterInitialization()— Registers one or more callback methods that should be executed after an object has been initialized. Initialization happafterNew()— Registers one or more callback methods that should be executed after a new object has been initialized, typically via thafterSave()— Registers one or more callback methods that should be executed after an object is saved to the database. This hook runsafterUpdate()— Registers one or more callback methods that should be executed after an existing object has been updated in the databaseafterValidation()— Registers one or more callback methods that should be executed after an object has been validated. This hook is useful fafterValidationOnCreate()— Registers one or more callback methods that should be executed after a new object has been validated (i.e., when runningafterValidationOnUpdate()— Registers one or more callback methods that should be executed after an existing object has been validated (i.e., when rautomaticValidations()— Controls whether automatic validations should be enabled for a specific model. By default, Wheels can automatically infebeforeCreate()— Registers method(s) that should be called before a new object is created. This allows you to modify or validate data, sebeforeDelete()— Registers method(s) that should be called before an object is deleted. This allows you to perform cleanup, enforce constbeforeSave()— Registers method(s) that should be called before an object is saved. This is useful for performing transformations, valibeforeUpdate()— Registers method(s) that should be called before an existing object is updated. This is useful for enforcing rules, tranbeforeValidation()— Registers method(s) that should be called before an object is validated. This hook is helpful when you want to adjust, nbeforeValidationOnCreate()— Registers method(s) that should be called before a new object is validated. This hook is useful when you want to preparebeforeValidationOnUpdate()— Registers method(s) that should be called before an existing object is validated. This hook is useful when you want to abelongsTo()— Sets up a belongsTo association between this model and another model. Use this when the current model contains a foreigndataSource()— dataSource() is a model configuration method used to override the default database connection for a specific model. ThishasMany()— Sets up a one-to-many association between the current model and another model. This allows you to easily fetch, join, anhasOne()— Defines a one-to-one relationship between two models. It means each instance of this model is linked to exactly one reconestedProperties()— Allows nested objects, arrays, or structs associated with a model to be automatically set from incoming params or otherproperty()— Lets you customize how model properties map to database columns or SQL expressions. By default, Wheels automatically mapprotectedProperties()— Used to protect one or more model properties from being set or modified through mass assignment operations. Mass assignmsetPrimaryKey()— The setPrimaryKey() function allows you to define which property (or properties) of a model represent the primary key insetPrimaryKeys()— Alias forsetPrimaryKey().setTableNamePrefix()— Allows you to add a prefix to the table name used by a model when performing SQL queries. This is useful if your databastable()— Used to tell Wheels which database table a model should connect to. Normally, Wheels automatically maps a model name tovalidate()— Used to register one or more validation methods that will be executed on a model object before it is saved to the databavalidateOnCreate()— Registers one or more validation methods that will be executed only when a new object is being inserted into the databasvalidateOnUpdate()— Registers one or more validation methods that will be executed only when an existing object is being updated in the datavalidatesConfirmationOf()— Validates that the value of the specified property also has an identical confirmation value.validatesExclusionOf()— Ensures that the value of a specified property is not included in a given list of disallowed values. This is commonly usvalidatesFormatOf()— Validates that the value of the specified property is formatted correctly by matching it against a regular expression usvalidatesInclusionOf()— Ensures that a property’s value exists in a predefined list of allowed values. It is commonly used for dropdowns, radiovalidatesLengthOf()— Validates that the value of the specified property matches the length requirements supplied.validatesNumericalityOf()— Ensures that a property’s value is numeric. You can also enforce additional constraints such as integer-only values, oddvalidatesPresenceOf()— Ensures that the specified property (or properties) exists and is not blank. It is commonly used to enforce required fievalidatesUniquenessOf()— Validates that the value of the specified property is unique in the database table.