Class ModelTask
Task class for creating and updating model files.
- AppShell
- BakeTask
- ModelTask
Copyright: Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
License: MIT License
Location: Cake/Console/Command/Task/ModelTask.php
Properties summary
-
$_modelNames
protectedarray
Holds the model names -
$_tables
protectedarray
Holds tables found on connection. -
$_validations
protectedarray
Holds validation method map. -
$path
publicstring
path to Model directory -
$skipTables
publicarray
Tables to skip when running all() -
$tasks
publicarray
tasks
Inherited Properties
Method Summary
-
_generatePossibleKeys() protected
Finds all possible keys to use on custom associations. -
_getModelObject() protected
Get a model object for a class name. -
_interactive() protected
Handles interactive baking -
_printAssociation() protected
Print out all the associations of a particular type -
all() public
Bake all models at once. -
bake() public
Assembles and writes a Model file. -
bakeFixture() public
Interact with FixtureTask to automatically bake fixtures when baking models. -
bakeTest() public
Assembles and writes a unit test file -
confirmAssociations() public
Interact with the user and confirm associations. -
doActsAs() public
Handles behaviors -
doAssociations() public
Handles associations -
doMoreAssociations() public
Interact with the user and generate additional non-conventional associations -
doValidation() public
Handles Generation and user interaction for creating validation. -
execute() public
Execution method always used for tasks -
fieldValidation() public
Does individual field validation handling. -
findBelongsTo() public
Find belongsTo relations and add them to the associations list. -
findDisplayField() public
interact with the user to find the displayField value for a model. -
findHasAndBelongsToMany() public
Find the hasAndBelongsToMany relations and add them to associations list -
findHasOneAndMany() public
Find the hasOne and hasMany relations and add them to associations list -
findPrimaryKey() public
Finds a primary Key in a list of fields. -
getAllTables() public
Get an Array of all the tables in the supplied connection will halt the script if no tables are found.
-
getName() public
Forces the user to specify the model he wants to bake, and returns the selected model name. -
getOptionParser() public
Gets the option parser instance and configures it. -
getTable() public
Interact with the user to determine the table name of a particular model -
inOptions() public
Generate a key value list of options and a prompt. -
initValidations() public
Populate the _validations array -
initialize() public
Override initialize -
listAll() public
outputs the a list of possible models or controllers from database
Method Detail
_generatePossibleKeys() protected ¶
_generatePossibleKeys( )
Finds all possible keys to use on custom associations.
Returns
Array of tables and possible keys
_getModelObject() protected ¶
_getModelObject( string $className , string $table = null )
Get a model object for a class name.
Parameters
- string $className
- Name of class you want model to be.
- string $table optional null
- Table name
Returns
_printAssociation() protected ¶
_printAssociation( string $modelName , string $type , string $associations )
Print out all the associations of a particular type
Parameters
- string $modelName
- Name of the model relations belong to.
- string $type
- Name of association you want to see. i.e. 'belongsTo'
- string $associations
- Collection of associations.
bake() public ¶
bake( string|object $name , array|boolean $data = array() )
Assembles and writes a Model file.
Parameters
- string|object $name
- Model name or object
- array|boolean $data optional array()
- if array and $name is not an object assume bake data, otherwise boolean.
Returns
bakeFixture() public ¶
bakeFixture( string $className , string $useTable = null )
Interact with FixtureTask to automatically bake fixtures when baking models.
Parameters
- string $className
- Name of class to bake fixture for
- string $useTable optional null
- Optional table name for fixture to use.
See
bakeTest() public ¶
bakeTest( string $className )
Assembles and writes a unit test file
Parameters
- string $className
- Model class name
Returns
confirmAssociations() public ¶
confirmAssociations( Model
$model , array $associations )
Interact with the user and confirm associations.
Parameters
-
Model
$model - Temporary Model instance.
- array $associations
- Array of associations to be confirmed.
Returns
Array of confirmed associations
doMoreAssociations() public ¶
doMoreAssociations( Model
$model , array $associations )
Interact with the user and generate additional non-conventional associations
Parameters
-
Model
$model - Temporary model instance
- array $associations
- Array of associations.
Returns
Array of associations.
doValidation() public ¶
doValidation( Model
$model )
Handles Generation and user interaction for creating validation.
Parameters
-
Model
$model - Model to have validations generated for.
Returns
validate Array of user selected validations.
fieldValidation() public ¶
fieldValidation( string $fieldName , array $metaData , string $primaryKey = 'id' )
Does individual field validation handling.
Parameters
- string $fieldName
- Name of field to be validated.
- array $metaData
- metadata for field
- string $primaryKey optional 'id'
- The primary key field.
Returns
Array of validation for the field.
findBelongsTo() public ¶
findBelongsTo( Model
$model , array $associations )
Find belongsTo relations and add them to the associations list.
Parameters
-
Model
$model - Model instance of model being generated.
- array $associations
- Array of in progress associations
Returns
Associations with belongsTo added in.
findDisplayField() public ¶
findDisplayField( array $fields )
interact with the user to find the displayField value for a model.
Parameters
- array $fields
- Array of fields to look for and choose as a displayField
Returns
Name of field to use for displayField or false if the user declines to choose
findHasAndBelongsToMany() public ¶
findHasAndBelongsToMany( Model
$model , array $associations )
Find the hasAndBelongsToMany relations and add them to associations list
Parameters
-
Model
$model - Model instance being generated
- array $associations
- Array of in-progress associations
Returns
Associations with hasAndBelongsToMany added in.
findHasOneAndMany() public ¶
findHasOneAndMany( Model
$model , array $associations )
Find the hasOne and hasMany relations and add them to associations list
Parameters
-
Model
$model - Model instance being generated
- array $associations
- Array of in progress associations
Returns
Associations with hasOne and hasMany added in.
findPrimaryKey() public ¶
findPrimaryKey( array $fields )
Finds a primary Key in a list of fields.
Parameters
- array $fields
- Array of fields that might have a primary key.
Returns
Name of field that is a primary key.
getAllTables() public ¶
getAllTables( string $useDbConfig = null )
Get an Array of all the tables in the supplied connection will halt the script if no tables are found.
Parameters
- string $useDbConfig optional null
- Connection name to scan.
Returns
Array of tables in the database.
getName() public ¶
getName( string $useDbConfig = null )
Forces the user to specify the model he wants to bake, and returns the selected model name.
Parameters
- string $useDbConfig optional null
- Database config name
Returns
The model name
getTable() public ¶
getTable( string $modelName , string $useDbConfig = null )
Interact with the user to determine the table name of a particular model
Parameters
- string $modelName
- Name of the model you want a table for.
- string $useDbConfig optional null
- Name of the database config you want to get tables from.
Returns
Table name
inOptions() public ¶
inOptions( array $options , string $prompt = null , integer $default = null )
Generate a key value list of options and a prompt.
Parameters
- array $options
- Array of options to use for the selections. indexes must start at 0
- string $prompt optional null
- Prompt to use for options list.
- integer $default optional null
- The default option for the given prompt.
Returns
Result of user choice.