Rose::DB::Object::Metadata objects store information about a single table in a database: the name of the table, the names and types of columns, any foreign or unique keys, etc. These metadata objects are also responsible for supplying information to, and creating object methods for, the Rose::DB::Object-derived objects to which they belong.

Once created, metadata objects can be populated manually or automatically. Both techniques are shown in the synopsis above. The automatic mode works by asking the database itself for the information. There are some caveats to this approach. See the auto-initialization section for more information.

Column objects are subclasses of Rose::DB::Object::Metadata::Column. They are intended to store as much information as possible about each column. The particular class of the column object created for a database column is determined by a mapping table. The column class, in turn, is responsible for creating the accessor/mutator method(s) for the column. When it creates these methods, the column class can use (or ignore) any information stored in the column object.

Foreign key objects are of the class Rose::DB::Object::Metadata::ForeignKey. They store information about columns that refer to columns in other tables that are fronted by their own Rose::DB::Object-derived classes. A foreign key object is responsible for creating accessor method(s) to fetch the foreign object from the foreign table.

Relationship objects are subclasses of Rose::DB::Object::Metadata::Relationship. They store information about a table's relationship to other tables that are fronted by their own Rose::DB::Object-derived classes. The particular class of the relationship object created for each relationship is determined by a mapping table. A relationship object is responsible for creating accessor method(s) to fetch the foreign objects from the foreign table.

Manual population of metadata objects can be tedious and repetitive. Nearly all of the information stored in a Rose::DB::Object::Metadata object exists in the database in some form. It's reasonable to consider simply extracting this information from the database itself, rather than entering it all manually. This automatic metadata extraction and subsequent Rose::DB::Object::Metadata object population is called "auto-initialization."

The example of auto-initialization in the synopsis above is the most succinct variant:

$meta->auto_initialize;

As you can read in the documentation for the auto_initialize method, that's shorthand for individually auto-initializing each part of the metadata object: columns, the primary key, unique keys, and foreign keys. But this brevity comes at a price. There are many caveats to auto-initialization.

In order to retrieve the information required for auto-initialization, a database connection must be opened and queries must be run. Sometimes these queries include complex joins. All of these queries must be successfully completed before the Rose::DB::Object-derived objects that the Rose::DB::Object::Metadata is associated with can be used.

In an environment like mod_perl, server start-up time is precisely when you want to do any expensive operations. But in a command-line script or other short-lived process, the overhead of auto-initializing many metadata objects may become prohibitive.

Also, don't forget that auto-initialization requires a database connection. Rose::DB::Object-derived objects can sometimes be useful even without a database connection (e.g., to temporarily store information that will never go into the database, or to synthesize data using object methods that have no corresponding database column). When using auto-initialization, this is not possible because the Rose::DB::Object-derived class won't even load if auto-initialization fails because it could not connect to the database.

First, auto-initialization cannot generate information that exists only in the mind of the programmer. The most common example is a relationship between two database tables that is either ambiguous or totally unexpressed by the database itself.

For example, if a foreign key constraint does not exist, the relationship between rows in two different tables cannot be extracted from the database, and therefore cannot be auto-initialized.

Even within the realm of information that, by all rights, should be available in the database, there are limitations. Although there is a handy DBI API for extracting metadata from databases, unfortunately, very few DBI drivers support it fully. Some don't support it at all. In almost all cases, some manual work is required to (often painfully) extract information from the database's "system tables" or "catalog."

More troublingly, databases do not always provide all the metadata that a human could extract from the series of SQL statement that created the table in the first place. Sometimes, the information just isn't in the database to be extracted, having been lost in the process of table creation. Here's just one example. Consider this MySQL table definition:

The "code" column has changed from CHAR(6) to VARCHAR(6). This is troublesome if you want the traditional semantics of a CHAR type, namely the padding with spaces of values that are less than the column length.

The "flag" column has changed from BOOLEAN to TINYINT(1). The default accessor method created for boolean columns has value coercion and formatting properties that are important to this data type. The default accessor created for integer columns lacks these constraints. The metadata object has no way of knowing that "flag" was supposed to be a boolean column, and thus makes the wrong kind of accessor method. It is thus possible to store, say, a value of "7" in the "flag" column. Oops.

The "bits" column has changed from BIT(5) to TINYINT(1). As in the case of the "flag" column above, this type change prevents the correct accessor method from being created. The default bitfield accessor method auto-inflates column values into Bit::Vector objects, which provide convenient methods for bit manipulation. The default accessor created for integer columns does no such thing.

Remember that the auto-initialization process can only consider the metadata actually stored in the database. It has no access to the original "create table" statement. Thus, the semantics implied by the original table definition are effectively lost.

Again, this is just one example of the kind of detail that can be lost in the process of converting your table definition into metadata that is stored in the database. Admittedly, MySQL is perhaps the worst case-scenario, having a well-deserved reputation for disregarding the wishes of table definitions. (The use of implicit default values for "NOT NULL" columns is yet another example.)

Thankfully, there is a solution to this dilemma. Remember that auto-initialization is actually a multi-step process hiding behind that single call to the auto_initialize method. To correct the sins of the database, simply break the auto-initialization process into its components. For example, here's how to correctly auto-initialize the "mytable" example above:

The price of auto-initialization is eternal vigilance. "What does that mean? Isn't auto-initialization supposed to save time and effort?" Well, yes, but at a cost. In addition to the caveats described above, consider what happens when a table definition changes.

"Ah ha!" you say, "My existing class will automatically pick up the changes the next time it's loaded! Auto-initialization at its finest!" But is it? What if you added a "NOT NULL" column with no default value? Yes, your existing auto-initialized class will pick up the change, but your existing code will no longer be able to save one these objects. Or what if you're using MySQL and your newly added column is one of the types described above that requires manual tweaking in order to get the desired semantics. Will you always remember to make this change?

Auto-initialization is not a panacea. Every time you make a change to your database schema, you must also revisit each affected Rose::DB::Object-derived class to at least consider whether or not the metadata needs to be corrected or updated.

The trade-off may be well worth it, but it's still something to think about. There is, however, a hybrid solution that might be even better. Continue on to the next section to learn more.

As described in the section above, auto-initializing metadata at runtime by querying the database has many caveats. An alternate approach is to query the database for metadata just once, and then generate the equivalent Perl code which can be pasted directly into the class definition in place of the call to auto_initialize.

Like the auto-initialization process itself, perl code generation has a convenient wrapper method as well as separate methods for the individual parts. All of the perl code generation methods begin with "perl_", and they support some rudimentary code formatting options to help the code conform to you preferred style. Examples can be found with the documentation for each perl_* method.

This hybrid approach to metadata population strikes a good balance between upfront effort and ongoing maintenance. Auto-generating the Perl code for the initial class definition saves a lot of tedious typing. From that point on, manually correcting and maintaining the definition is a small price to pay for the decreased start-up cost, the ability to use the class in the absence of a database connection, and the piece of mind that comes from knowing that your class is stable, and won't change behind your back in response to an "action at a distance" (i.e., a database schema update).

Get or set a boolean value that indicates whether or not the prime_caches method will be called from within the initialize method. The default is true if the MOD_PERL environment variable ($ENV{'MOD_PERL'}) is set to a true value, false otherwise.

Given the column type string TYPE, return the name of the Rose::DB::Object::Metadata::Column-derived class used to store metadata and create the accessor method(s) for columns of that type. If a CLASS is passed, the column type TYPE is mapped to CLASS. In both cases, the TYPE argument is automatically converted to lowercase.

If passed MAP (a list of type/class pairs or a reference to a hash of the same) then MAP replaces the current column type mapping. Returns a list of type/class pairs (in list context) or a reference to the hash of type/class mappings (in scalar context).

If passed MAP (a list of name/class pairs or a reference to a hash of the same) then MAP replaces the current mapping. Returns a list of name/class pairs (in list context) or a reference to the hash of name/class mappings (in scalar context).

Get or set the default name of the base class used by this metadata class when generating a manager classes. The default value is Rose::DB::Object::Manager. See the default_manager_base_class()object method to override this value for a specific metadata object.

This class method should return a reference to a subroutine that maps column names to method names, or false if it does not want to do any custom mapping. The default implementation returns zero (0).

If defined, the subroutine should take four arguments: the metadata object, the column name, the column method type, and the method name that would be used if the mapper subroutine did not exist. It should return a method name.

A Rose::DB-derived object used to determine which data source the cached metadata will be generated on behalf of. (Each data source has its own set of cached metadata.) This parameter is optional. If it is not passed, then the Rose::DB-derived object returned by the init_db method for each class will be used instead.

Given the relationship type string TYPE, return the name of the Rose::DB::Object::Metadata::Relationship-derived class used to store metadata and create the accessor method(s) for relationships of that type.

Get or set the hash that maps relationship type strings to the names of the Rose::DB::Object::Metadata::Relationship-derived classes used to store metadata and create object methods fetch and/or manipulate objects from foreign tables.

If passed MAP (a list of type/class pairs or a reference to a hash of the same) then MAP replaces the current relationship type mapping. Returns a list of type/class pairs (in list context) or a reference to the hash of type/class mappings (in scalar context).

Returns (or creates, if needed) the single Rose::DB::Object::Metadata associated with a particular Rose::DB::Object-derived class, modifying or initializing it according to PARAMS, where PARAMS are name/value pairs.

Any object method is a valid parameter name, but PARAMS must include a value for the class parameter, since that's how Rose::DB::Object::Metadata objects are mapped to their corresponding Rose::DB::Object-derived class.

Add the columns specified by ARGS to the list of columns for the table. Returns the list of columns added in list context, or a reference to an array of columns added in scalar context. Columns can be specified in ARGS in several ways.

If an argument is a plain scalar, it is taken as the name of a scalar column. A column object of the class returned by the method call $obj->column_type_class('scalar') is constructed and then added.

Otherwise, only name/value pairs are considered, where the name is taken as the column name and the value must be a reference to a hash.

If the hash contains the key "primary_key" with a true value, then the column is marked as a primary_key_member and the column name is added to the list of primary key columns by calling the add_primary_key_column method with the column name as its argument.

If the hash contains the key "alias", then the value of that key is used as the alias for the column. This is a shorthand equivalent to explicitly calling the alias_column column method.

If the hash contains the key "temp" and its value is true, then the column is actually added to the list of non-persistent columns.

If the hash contains a key with the same name as a column trigger event type (e.g., "on_set", "on_load", "inflate") then the value of that key must be a code reference or a reference to an array of code references, which will be added to the list of the column's triggers for the specified event type.

If the hash contains the key "methods", then its value must be a reference to an array or a reference to a hash. The auto_method_types of the column are then set to the values of the referenced array, or the keys of the referenced hash. The values of the referenced hash are used to set the method_name for their corresponding method types.

If the hash contains the key "add_methods", then its value must be a reference to an array or a reference to a hash. The values of the referenced array or the keys of the referenced hash are added to the column's auto_method_types. The values of the referenced hash are used to set the method_name for their corresponding method types.

If the "methods" and "add_methods" keys are both set, a fatal error will occur.

Then the column_type_class method is called with the value of the "type" hash key as its argument (or "scalar" if that key is missing), returning the name of a column class. Finally, a new column object of that class is constructed and is passed all the remaining pairs in the hash reference, along with the name and type of the column. That column object is then added to the list of columns.

This is done until there are no more arguments to be processed, or until an argument does not conform to one of the required formats, in which case a fatal error occurs.

Otherwise, only name/value pairs are considered, where the name is taken as the foreign key name and the value must be a reference to a hash.

If the hash contains the key "methods", then its value must be a reference to an array or a reference to a hash. The auto_method_types of the foreign key are then set to the values of the referenced array, or the keys of the referenced hash. The values of the referenced hash are used to set the method_name for their corresponding method types.

If the hash contains the key "add_methods", then its value must be a reference to an array or a reference to a hash. The values of the referenced array or the keys of the referenced hash are added to the foreign key's auto_method_types. The values of the referenced hash are used to set the method_name for their corresponding method types.

If the "methods" and "add_methods" keys are both set, a fatal error will occur.

A new Rose::DB::Object::Metadata::ForeignKey object is constructed and is passed all the remaining pairs in the hash reference, along with the name of the foreign key as the value of the "name" parameter. That foreign key object is then added to the list of foreign keys.

This is done until there are no more arguments to be processed, or until an argument does not conform to one of the required formats, in which case a fatal error occurs.

For each foreign key added, a corresponding relationship with the same name is added if it does not already exist. The relationship type is determined by the value of the foreign key object's relationship attribute. The default is "many to one". The class of the relationship is chosen by calling relationship_type_class with the relationship type as an argument.

Otherwise, only name/value pairs are considered, where the name is taken as the relationship name and the value must be a reference to a hash.

If the hash contains the key "methods", then its value must be a reference to an array or a reference to a hash. The auto_method_types of the relationship are then set to the values of the referenced array, or the keys of the referenced hash. The values of the referenced hash are used to set the method_name for their corresponding method types.

If the hash contains the key "add_methods", then its value must be a reference to an array or a reference to a hash. The values of the referenced array or the keys of the referenced hash are added to the relationship's auto_method_types. The values of the referenced hash are used to set the method_name for their corresponding method types.

If the "methods" and "add_methods" keys are both set, a fatal error will occur.

Then the relationship_type_class method is called with the value of the type hash key as its argument, returning the name of a relationship class.

Finally, a new relationship object of that class is constructed and is passed all the remaining pairs in the hash reference, along with the name and type of the relationship. That relationship object is then added to the list of relationships.

This is done until there are no more arguments to be processed, or until an argument does not conform to one of the required formats, in which case a fatal error occurs.

Otherwise, an argument must be a single column name or a reference to an array of column names that make up a unique key. A new Rose::DB::Object::Metadata::UniqueKey is created, with its parent set to the metadata object itself, and then the unique key object is added to this list of unique keys for this class.

Set the alias for the column named NAME to ALIAS. It is sometimes necessary to use an alias for a column because the column name conflicts with an existing Rose::DB::Object method name.

For example, imagine a column named "save". The Rose::DB::Object API already defines a method named save, so obviously that name can't be used for the accessor method for the "save" column. To solve this, make an alias:

Get or set the boolean flag that indicates whether or not the associated Rose::DB::Object-derived class should try to inline column values that DBI does not handle correctly when they are bound to placeholders using bind_columns. The default value is false.

Enabling this flag reduces the performance of the update and insert operations on the Rose::DB::Object-derived object. But it is sometimes necessary to enable the flag because some DBI drivers do not (or cannot) always do the right thing when binding values to placeholders in SQL statements. For example, consider the following SQL for the Informix database:

Get or set the database catalog for this class. This setting will override any setting in the db object. Use this method only if you know that the class will always point to a specific catalog, regardless of what the Rose::DB-derived database handle object specifies.

Returns the name of the Rose::DB::Object-derived class associated with the catalog, schema, and table specified by the name/value paris in PARAMS. Catalog and/or schema maybe omitted if unknown or inapplicable, and the "best" match will be returned. Returns undef if there is no class name registered under the specified PARAMS.

Note: This method may also be called as a class method, but may require explicit catalog and/or schema arguments when dealing with databases that support these concepts and have default implicit values for them.

Get or set the column named NAME. If just NAME is passed, the Rose::DB::Object::Metadata::Column-derived column object for the column of that name is returned. If no such column exists, undef is returned.

If both NAME and COLUMN are passed, then COLUMN must be a Rose::DB::Object::Metadata::Column-derived object. COLUMN has its name set to NAME, and is then stored as the column metadata object for NAME, replacing any existing column.

If both NAME and HASHREF are passed, then the combination of NAME and HASHREF must form a name/value pair suitable for passing to the add_columns method. The new column specified by NAME and HASHREF replaces any existing column.

Get or set the hash that maps column names to their aliases. If passed MAP (a list of name/value pairs or a reference to a hash) then MAP replaces the current alias mapping. Returns a reference to the hash that maps column names to their aliases.

Get or set the code reference to the subroutine used to map column names to method names. If undefined, then the init_column_name_to_method_name_mapper class method is called in order to initialize it. If still undefined or false, then the "default" method name is used.

If defined, the subroutine should take four arguments: the metadata object, the column name, the column method type, and the method name that would be used if the mapper subroutine did not exist. It should return a method name.

If a convention manager name is passed, then the corresponding class is looked up in the convention manager class map, a new object of that class is constructed, its meta attribute set to this metadata object, and it is used as the convention manager for this class. If there is no class mapped to NAME, a fatal error will occur.

Get or set a boolean value that indicates whether or not the class associated with this metadata object will save related objects when the parent object is saved. See the documentation for Rose::DB::Object's save() method for details. The default value is false.

Get or set a boolean value that indicates whether or not the class associated with this metadata object will load speculatively by default. See the documentation for Rose::DB::Object's load() method for details. The default value is false.

Get or set a boolean value that indicates whether or not the class associated with this metadata object will update only an object's modified columns by default (instead of updating all columns). See the documentation for Rose::DB::Object's update() method for details. The default value is false.

Get or set the error mode of the Rose::DB::Object that fronts the table described by this Rose::DB::Object::Metadata object. If the error mode is false, then it defaults to the return value of the init_error_mode method, which is "fatal" by default.

The error mode determines what happens when a Rose::DB::Object method encounters an error. The "return" error mode causes the methods to behave as described in the Rose::DB::Object documentation. All other error modes cause an action to be performed before (possibly) returning as per the documentation (depending on whether or not the "action" is some variation on "throw an exception.")

Get or set the foreign key named NAME. NAME should be the name of the thing being referenced by the foreign key, not the name of any of the columns that make up the foreign key. If called with just a NAME argument, the foreign key stored under that name is returned. Undef is returned if there is no such foreign key.

If both NAME and FOREIGNKEY are passed, then FOREIGNKEY must be a Rose::DB::Object::Metadata::ForeignKey-derived object. FOREIGNKEY has its name set to NAME, and is then stored, replacing any existing foreign key with the same name.

If both NAME and HASHREF are passed, then the combination of NAME and HASHREF must form a name/value pair suitable for passing to the add_foreign_keys method. The new foreign key specified by NAME and HASHREF replaces any existing foreign key with the same name.

This method is the same as generate_primary_key_values except that it only returns the generated value for the first primary key column, rather than the entire list of values. Use this method only when there is a single primary key column (or not at all).

Given the Rose::DB-derived object DB, generate and return a list of new primary key column values for the table described by this metadata object.

If a primary_key_generator is defined, it will be called (passed this metadata object and the DB) and its value returned.

If no primary_key_generator is defined, new primary key values will be generated, if possible, using the native facilities of the current database. Note that this may not be possible for databases that auto-generate such values only after an insertion. In that case, undef will be returned.

Get or set a boolean value that indicates whether or not the auto_init_unique_keys method will create unique keys for unique indexes that have predicates. The default value is false. This feature is currently only supported for PostgreSQL.

Predicated unique indexes differ semantically from unpredicated unique indexes in that predicates generally cause the index to only apply to part of a table. Rose::DB::Object expects unique indexes to uniquely identify a row within a table. Predicated indexes that fail to do so due to their predicates should therefore not have Rose::DB::Object::Metadata::UniqueKey objects created for them, thus the false default for this attribute.

Initialize the Rose::DB::Object-derived class associated with this metadata object by creating accessor methods for each column and foreign key. The table name and the primary_key_columns must be defined or a fatal error will occur.

If any column name in the primary key or any of the unique keys does not exist in the list of columns, then that primary or unique key is deleted. (As per the above, this will trigger a fatal error if any column in the primary key is not in the column list.)

ARGS, if any, are passed to the call to make_methods that actually creates the methods.

Foreign keys and relationships with the type "one to one" or "many to one" both encapsulate essentially the same information. They are kept in sync when this method is called by setting the foreign_key attribute of each "one to one" or "many to one" relationship object to be the corresponding foreign key object.

Foreign keys and relationships with the type "one to one" or "many to one" both encapsulate essentially the same information. They are kept in sync when this method is called by setting the foreign_key attribute of each "one to one" or "many to one" relationship object to be the corresponding foreign key object.

If a relationship corresponds exactly to a foreign key, and that foreign key already made an object method, then the relationship is not asked to make its own method.

Get or set the default name of the base class used by this specific metadata object when generating a manager class, using either the perl_manager_class or make_manager_class methods. The default value is determined by the default_manager_base_class|/default_manager_base_class()class method.

Given a Rose::DB::Object::Metadata::Column-derived column object and a column type name, return the corresponding method name that should be used for it. Several entities are given an opportunity to determine the name. They are consulted in the following order.

Get or set the full list of non-persistent columns. If ARGS are passed, the non-persistent column list is cleared and then ARGS are passed to the add_nonpersistent_columns method.

Returns a list of non-persistent column objects in list context, or a reference to an array of non-persistent column objects in scalar context.

Non-persistent columns allow the creation of object attributes and associated accessor/mutator methods exactly like those associated with columns, but without ever sending any of these attributes to (or pulling any these attributes from) the database.

Non-persistent columns are tracked entirely separately from columns. Adding, deleting, and listing non-persistent columns has no affect on the list of normal (i.e., "persistent") columns.

You cannot query the database (e.g., using Rose::DB::Object::Manager) and filter on a non-persistent column; non-persistent columns do not exist in the database. This feature exists solely to leverage the method creation abilities of the various column classes.

Returns a list (in list context) or a reference to the array (in scalar context) of the names of the "set" methods for all the non-persistent columns, in the order that the columns are returned by nonpersistent_column_names.

Get or set a reference to a subroutine or a reference to an array of code references that will be called just after the initialize method runs. Each referenced subroutine will be passed the metadata object itself and any arguments passed to the call to initialize.

Get or set a reference to a subroutine or a reference to an array of code references that will be called just before the initialize method runs. Each referenced subroutine will be passed the metadata object itself and any arguments passed to the call to initialize.

Returns all of the columns that make up the primary key. Each column is a Rose::DB::Object::Metadata::Column-derived column object if a column object with the same name exists, or just the column name otherwise. In scalar context, a reference to an array of columns is returned. In list context, a list is returned.

Get or set the subroutine used to generate new primary key values for the primary key columns of this table. The subroutine will be passed two arguments: the current metadata object and the Rose::DB-derived object that points to the current database.

The subroutine is expected to return a list of values, one for each primary key column. The values must be in the same order as the corresponding columns returned by primary_key_columns. (i.e., the first value belongs to the first column returned by primary_key_columns, the second value belongs to the second column, and so on.)

Get or set the list of database sequence names used to populate the primary key columns. The sequence names must be in the same order as the primary_key_columns. NAMES may be a list or reference to an array of sequence names. Returns a list (in list context) or reference to the array (in scalar context) of sequence names.

If you do not set this value, it will be derived for you based on the name of the primary key columns. In the common case, you do not need to be concerned about this method. If you are using the built-in SERIAL or AUTO_INCREMENT types in your database for your primary key columns, everything should just work.

By default, secondary metadata derived from the attributes of this object is created and cached on demand. Call this method to pre-cache this metadata all at once. This method is useful when running in an environment like mod_perl where it's advantageous to load as much data as possible on start-up.

A Rose::DB-derived object used to determine which data source the cached metadata will be generated on behalf of. (Each data source has its own set of cached metadata.) This parameter is optional. If it is not passed, then the Rose::DB-derived object returned by the init_db method for this class will be used instead.

Get or set the relationship named NAME. If just NAME is passed, the Rose::DB::Object::Metadata::Relationship-derived relationship object for that NAME is returned. If no such relationship exists, undef is returned.

If both NAME and RELATIONSHIP are passed, then RELATIONSHIP must be a Rose::DB::Object::Metadata::Relationship-derived object. RELATIONSHIP has its name set to NAME, and is then stored as the relationship metadata object for NAME, replacing any existing relationship.

If both NAME and HASHREF are passed, then the combination of NAME and HASHREF must form a name/value pair suitable for passing to the add_relationships method. The new relationship specified by NAME and HASHREF replaces any existing relationship.

Get or set the database schema for this class. This setting will override any setting in the db object. Use this method only if you know that the class will always point to a specific schema, regardless of what the Rose::DB-derived database handle object specifies.

Set up all the metadata for this class in a single method call. This method is a convenient shortcut. It does its work by delegating to other methods.

The setup() method does nothing if the metadata object is already initialized (according to the is_initialized method).

PARAMS are method/arguments pairs. In general, the following transformations apply.

Given a method/arrayref pair:

METHOD => [ ARG1, ARG2 ]

The arguments will be removed from their array reference and passed to METHOD like this:

$meta->METHOD(ARG1, ARG2);

Given a method/value pair:

METHOD => ARG

The argument will be passed to METHOD as-is:

$meta->METHOD(ARG);

There are two exceptions to these transformation rules.

If METHOD is "unique_key" or "add_unique_key" and the argument is a reference to an array containing only non-reference values, then the array reference itself is passed to the method. For example, this pair:

unique_key => [ 'name', 'status' ]

will result in this method call:

$meta->unique_key([ 'name', 'status' ]);

(Note that these method names are singular. This exception does not apply to the plural variants, "unique_keys" and "add_unique_keys".)

If METHOD is "helpers", then the argument is dereferenced (if it's an array reference) and passed on to Rose::DB::Object::Helpers. That is, this:

Method names may appear more than once in PARAMS. The methods are called in the order that they appear in PARAMS, with the exception of the initialize (or auto_initialize) method, which is always called last.

If "initialize" is not one of the method names, then it will be called automatically (with no arguments) at the end. If you do not want to pass any arguments to the initialize method, standard practice is to omit it.

If "auto_initialize" is one of the method names, then the auto_initialize method will be called instead of the initialize method. This is useful if you want to manually set up a few pieces of metadata, but want the auto-initialization system to set up the rest.

The name "auto" is considered equivalent to "auto_initialize", but any arguments are ignored unless they are encapsulated in a reference to an array. For example, these are equivalent:

$meta->setup(
table => 'mytable',
# Call auto_initialize() with no arguments
auto_initialize => [],
);
# This is another way of writing the same thing as the above
$meta->setup(
table => 'mytable',
# The value "1" is ignored because it's not an arrayref,
# so auto_initialize() will be called with no arguments.
auto => 1,
);

Finally, here's a full example of a setup() method call followed by the equivalent "long-hand" implementation.

These methods are associated with the auto-initialization process. Calling any of them will cause the auto-initialization code to be loaded, which costs memory. This should be considered an implementation detail for now.

Regardless of the implementation details, you should still avoid calling any of these methods unless you plan to do some auto-initialization. No matter how generic they may seem (e.g., default_perl_indent), rest assured that none of these methods are remotely useful unless you are doing auto-initialization.

Get or set the default style of the unique key initialization used in the Perl code generated by the perl_unique_keys_definition method. STYLE must be "array" or "object". The default value is "array". See the perl_unique_keys_definition method for examples of the two styles.

Auto-generate Rose::DB::Object::Metadata::Column-derived objects for each column in the table. Note that this method does not modify the metadata object's list of columns. It simply returns a list of column objects. Calling this method in void context will cause a fatal error.

Returns a list of column objects (in list context) or a reference to a hash of column objects, keyed by column name (in scalar context). The hash reference return value is intended to allow easy modification of the auto-generated column objects. Example:

Auto-generate Rose::DB::Object::Metadata::ForeignKey objects for each foreign key in the table. Note that this method does not modify the metadata object's list of foreign_keys. It simply returns a list of foreign key objects. Calling this method in void context will cause a fatal error. A warning will be issued if a foreign key could not be generated because no Rose::DB::Object-derived class was found for the foreign table.

PARAMS are optional name/value pairs. If a no_warnings parameter is passed with a true value, then the warning described above will not be issued.

Returns a list of foreign key objects (in list context) or a reference to an array of foreign key objects (in scalar context).

If you do not want to inspect or modify the auto-generated foreign keys, but just want them to populate the metadata object's foreign_keys list, you should use the auto_init_foreign_keys method instead.

Note: This method works with MySQL only when using the InnoDB storage type.

Auto-generate Rose::DB::Object::Metadata::UniqueKey objects for each unique key in the table. Note that this method does not modify the metadata object's list of unique_keys. It simply returns a list of unique key objects. Calling this method in void context will cause a fatal error.

Returns a list of unique key objects (in list context) or a reference to an array of unique key objects (in scalar context).

If you do not want to inspect or modify the auto-generated unique keys, but just want them to populate the metadata object's unique_keys list, you should use the auto_init_unique_keys method instead.

Returns a list (in list context) or a reference to an array (in scalar context) of the names of the columns that make up the primary key for this table. Note that this method does not modify the metadata object's primary_key. It simply returns a list of column names. Calling this method in void context will cause a fatal error.

By default, if a class is a map class (according to the is_map_class method of the convention manager), then relationships directly between that class and the current class will not be created. Set this parameter to true to allow such relationships to be created.

Note: If some classes that are not actually map classes are being skipped, you should not use this parameter to force them to be included. It's more appropriate to make your own custom convention manager subclass and then override the is_map_class method to make the correct determination.

If true, then any database connections retained by the metadata objects belonging to the various Rose::DB::Object-derived classes participating in the auto-initialization process will remain connected until an explicit call to the clear_all_dbs class method.

A boolean value or a reference to an array of relationship type names. If set to a simple boolean value, then the all types of relationships will be considered for auto-initialization. If set to a list of relationship type names, then only relationships of those types will be considered. Defaults to true.

A boolean value indicating whether or not unique key metadata will be auto-initialized. Defaults to true.

During initialization, if one of the columns has a method name that clashes with a reserved method name, then the column_alias_generator will be called to remedy the situation by aliasing the column. If the name still conflicts, then a fatal error will occur.

Auto-generate Rose::DB::Object::Metadata::Column objects for this table, then populate the list of columns. PARAMS are optional name/value pairs. If a replace_existing parameter is passed with a true value, then the auto-generated columns replace any existing columns. Otherwise, any existing columns are left as-is.

Auto-generate Rose::DB::Object::Metadata::ForeignKey objects for this table, then populate the list of foreign_keys. PARAMS are optional name/value pairs. If a replace_existing parameter is passed with a true value, then the auto-generated foreign keys replace any existing foreign keys. Otherwise, any existing foreign keys are left as-is.

Note: This method works with MySQL only when using the InnoDB storage type.

Auto-retrieve the names of the columns that make up the primary key for this table, then populate the list of primary_key_column_names. A fatal error will occur unless at least one primary key column name could be retrieved.

By default, if a class is a map class (according to the is_map_class method of the convention manager), then relationships directly between that class and the current class will not be created. Set this parameter to true to allow such relationships to be created.

Note: If some classes that are not actually map classes are being skipped, you should not use this parameter to force them to be included. It's more appropriate to make your own custom convention manager subclass and then override the is_map_class method to make the correct determination.

A reference to an array of relationship type names. Only relationships of these types will be created. If omitted, relationships of all types will be created. If passed a reference to an empty array, no relationships will be created.

A many-to-many relationship is created between Local and Remote if there exists a map class (according to the convention manager's is_map_class method) with exactly two foreign keys, one pointing to Local and on pointing to Remote. The relationship name is generated by creating a plural version of the name of the foreign key in the map class that points to Remote.

In all cases, if there is an existing, semantically identical relationship, then a new relationship is not auto-generated. Similarly, any existing methods with the same names are not overridden by methods associated with auto-generated relationships.

Auto-generate Rose::DB::Object::Metadata::UniqueKey objects for this table, then populate the list of unique_keys. PARAMS are name/value pairs. If a replace_existing parameter is passed with a true value, then the auto-generated unique keys replace any existing unique keys. Otherwise, any existing unique keys are left as-is.

Get or set the code reference to the subroutine used to alias columns have, or would generate, one or more method names that clash with reserved method names.

The subroutine should take two arguments: the metadata object and the column name. The $_ variable will also be set to the column name at the time of the call. The subroutine should return an alias for the column.

The default column alias generator simply appends the string "_col" to the end of the column name and returns that as the alias.

Each foreign key must have a name that is unique within the class. By default, this name will also be the name of the method generated to access the object referred to by the foreign key, so it must be unique among method names in the class as well.

The default foreign key name generator uses the following algorithm:

If the foreign key has only one column, and if the name of that column ends with an underscore and the name of the referenced column, then that part of the column name is removed and the remaining string is used as the foreign key name. For example, given the following tables:

The foreign key name would be "category", which is the name of the referring column ("category_id") with an underscore and the name of the referenced column ("_id") removed from the end of it.

If the foreign key has only one column, but it does not meet the criteria described above, then "_object" is appended to the name of the referring column and the resulting string is used as the foreign key name.

If the foreign key has more than one column, then the foreign key name is generated by replacing double colons and case-transitions in the referenced class name with underscores, and then converting to lowercase. For example, if the referenced table is fronted by the class My::TableOfStuff, then the generated foreign key name would be "my_table_of_stuff".

In all of the scenarios above, if the generated foreign key name is still not unique within the class, then a number is appended to the end of the name. That number is incremented until the name is unique.

In practice, rather than setting a custom foreign key name generator, it's usually easier to simply set the foreign key name(s) manually after auto-initializing the foreign keys (but before calling initialize or auto_initialize, of course).

Auto-initialize the columns, primary key, foreign keys, and unique keys, then return the Perl source code for a complete Rose::DB::Object-derived class definition. PARAMS are optional name/value pairs that may include the following:

If true, then the generated class definition will include a call to the setup method. Otherwise, the generated code will contain individual methods calls. The default value for this parameter is true; the setup method is the recommended way to initialize a class.

package Code;
use base qw(Rose::DB::Object);
__PACKAGE__->meta->auto_initialize;
package Category;
use base qw(Rose::DB::Object);
# Explicit table name required because the class name
# does not match up with the table name in this case.
__PACKAGE__->meta->table('topics');
__PACKAGE__->meta->auto_initialize;
package Product;
use base qw(Rose::DB::Object);
__PACKAGE__->meta->auto_initialize;
package Price;
use base qw(Rose::DB::Object);
__PACKAGE__->meta->auto_initialize;

Returns a Perl class definition for a Rose::DB::Object::Manager-derived class to manage objects of this class. If a single string is passed, it is taken as the value of the base_name parameter. PARAMS are optional name/value pairs that may include the following:

The name of a single class or a reference to an array of class names to be included in the @ISA array for the manager class. One of these classes must inherit from Rose::DB::Object::Manager. Defaults to the return value of the default_manager_base_class()object method.

Determines the style the initialization used in the generated Perl code. STYLE must be "array" or "object". The default is determined by the return value of the class method default_perl_unique_key_style.