Calling this function also generates a number of methods and attributes in the calling class.

First, it generates one attribute for each column in the associated table. Of course, this assumes that your columns are named in such a way as to be usable as Perl methods.

It also generates a predicate for each attribute, where the predicate is the column named prefixed with "has_". So for a column named "user_id", you get a user_id() attribute and a has_user_id() predicate.

These column-named attributes do not have a public setter method. If you want to change the value of these attributes, you need to use the update() method.

The has_one() function declares a relationship between the calling class's table and another table. The method it creates returns an object of the foreign table's class, or undef or none exists.

With the single-argument form, you can simply pass a single Fey::Table object. This works when there is a single foreign key between the calling class's table and the table passed to has_one().

With a single argument, the generated attribute will be named as lc $has_one_table->name(), and caching will be turned on.

If you want to change any of the defaults, you can use the multi-argument form. In this case, the first argument is the name of the attribute or method to add. Then you can specify various parameters by name. You must specify a table, of course.

The fk parameter is required when there is more than one foreign key between the two tables. Finally, you can turn off caching by setting cache to a false value.

When caching is enabled, the object for the foreign table is only fetched once, and is cached afterwards. This is independent of the object caching for a particular class. If you turn off caching, then the object is fetched every time the method is called.

Also, a private clearer method is created when caching is enabled, of the form $object->_clear_$name().

The undef parameter allows you to explicitly say whether the attribute can be undefined. Normally this is calculated by looking at the foreign key and seeing if any of the source columns are nullable.

The handles parameter works exactly like it does for any Moose attribute, but it only works if cache is true, since otherwise the relationship is implemented via a simple method, not a Moose attribute.

This is an alternative form of has_one() that lets you declare a relationship to another table via an arbitrary SELECT statement.

In this form, you provide a query object to define the SQL used to fetch the foreign row. You can provide a bind_params parameter as a code reference, which will be called as a method on your object. It is expected to return one or more bind parameters. The cache parameter works exactly the same as in the first form of has_one().

In this form the undef parameter defaults to true, but you can set it to a false value.

Note that if you want to provide bind_params for the SQL you provide, you need to make sure it has placeholders.

The has_many() function declares a relationship between the calling class's table and another table, just like has_one(). The method it creates returns a Fey::Object::Iterator::FromSelect of the foreign table's objects.

With the single-argument form, you can simply pass a single Fey::Table object. This works when there is a single foreign key between the calling class's table and the table passed to has_many().

With a single argument, the generated attribute will be named as lc $has_one_table->name(), and caching will be turned off. There will be no specific order to the results returned.

If you want to change any of the defaults, you can use the multi-argument form. In this case, the first argument is the name of the attribute or method to add. Then you can specify various parameters by name. You must specify a table, of course.

The fk parameter is required when there is more than one foreign key between the two tables. Finally, you can turn on caching by setting cache to a true value.

The query() function declares a method based on the given query. This works much like declaring an attribute with the FromSelect metaclass, but the value returned from the query is not stored in the object.

The transform() function declares an inflator, deflator, or both for the specified column. The inflator will be used to wrap the normal accessor for the column. You'd generally use this to turn a raw value from the DBMS into an object, for example:

The inflator (and deflator) coderef you specify will be called as a method on the object (or class). This lets you get at other attributes for the object if needed.

When a column is inflated, a new attribute is created to allow you to get at the raw data by suffixing the column name with "_raw". Given the above inflator, a creation_date_raw() attribute would be created.

If the column in question is nullable your inflator should be prepared to handle an undef value for the column.

Deflators are used to transform objects passed to update() or insert() into values suitable for passing to the DBMS: