./script/solar make-model
Vendor_Model_TableName
[--table=table_name
] [--extends=Vendor_Model_ParentClass
] [--connect=true|false
]
./script/solar make-model
Vendor_Model_TableName
The above command creates one model class set using the
default SQL database connection, and picks the table name from the
class name. In the above command, it would look for
table_name
in the database; implicitly, the
command converts studly-caps to underscores. It also uses the
Vendor_Sql_Model
class set as the parent class
set.
$./script/solar make-model
Making model 'Vendor_Model_TableName
Vendor_Model_TableName
'. Will write to 'SYSTEM
/include/'. Using table 'table_name
'. Not using inheritance. Making class directory ... done. Writing model class ... done. Writing record class ... done. Writing collection class ... done. Connecting to database for metadata ...connected. Fetching table cols ... done. Fetching index info ... done. Writing metadata class ... done. Creating locale directory ... done. Saving locale file for en_US ... done. Done. $
What is going on here?
-
The command creates three classes and their respective directory:
Vendor_Model_TableName
(the model mapper class),Vendor_Model_TableName_Record
(the model record class),Vendor_Model_TableName_Collection
(the class for a collection of model records). -
The command then connects to the database to retrieve column and index information on the table. This metadata is then stored in a
Vendor_Model_TableName_Metadata
class. If you call make-model again, this metadata class will be overwritten, so do not modify it yourself. (You can tell the command not to connect by passing--connect=false
.) -
Finally, using the metadata, the command builds an initial locale file for the model.
./script/solar make-model
Vendor_Model_OtherName
--table=table_name
The above command creates one model class set using the default SQL database connection, and uses an explicitly-identified table name from the database.
./script/solar make-model
Vendor_Model_TableName
--extends=Vendor_Model_ParentClass
The above command creates one model class set using the default SQL database connection, and uses an implicitly-identified table taken from the class name.
However, instead of using Vendor_Sql_Model
as its parent class set, it uses Vendor_Model_ParentClass
for its parentage. By default, this means the created model
will use the same table as Vendor_Model_ParentClass
,
and it will enable single-table inheritance.
./script/solar make-model
Vendor_Model
_*
The trailing _*
wildcard in the above command
creates one model class set for each table in the default SQL
database connection. The table names will be used for the class
name suffixes. For example, if there are tables
foo
and zim_gir
in the
database, the command will create
Vendor_Model_Foo
and
Vendor_Model_ZimGir
model class sets.