The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Rose::DBx::Garden::Catalyst::Form::Metadata - RHTMLO Form class metadata

DESCRIPTION

Rose::DBx::Garden::Catalyst::Form::Metadata interrogates and caches interrelationships between Form classes and the RDBO classes they represent.

You typically access an instance of this class via the metadata() method in your Form class.

METHODS

init

Overrides base init() method to build metadata.

Boolean indicating whether the View should provide links to related tables based on RDBO foreign_keys() and relationships().

Default is true.

Boolean indicating whether the YUI DataTable should show related unique field values rather than the foreign keys to which they refer.

Default is true.

show_relationships

Boolean indicating whether the View should provide links to related tables based on RDBO relationship method names that do not have corresponding field names.

init_controller_prefix

The default is 'RDGC'.

init_labels

Should return a hashref of method (field) names to labels. Useful for giving labels to non-fields like relationship names and methods listed in yui_datatable_methods().

init_object_class

Should return the name of the RDBO class the Form class represents. Default is the Form class name less the ::Form part.

init_field_uris

Should return a hashref of field names to a value that will be passed to Catalyst's uri_for() method. Used primarily for per-column click behaviour in a YUI DataTable.

init_default_sort_by

Should return the name of the field to sort by in initial yui_datatable.

Default is null (emptry string) which will make it default to the primary key.

init_takes_object_as_argument

Set hash ref of method names that take the parent RDBO object as a single argument. Used in YUI serialize().

field_uri( field_name )

Returns the value from field_uris() for key field_name if such a key exists. Otherwise, returns undef.

Used by show_related_fields_using(), this method should return a hashref of field_name to method_name where field_name is a field in the Form and method_name is a method name in the foreign object_class.

The default is an empty hashref, which means that show_related_fields_using() will take the first unique column it can find as the method_name.

relationships

Returns arrayref of object_class() foreign_keys() and relationships(). These are guaranteed to be unique with regard to name, so any relationships that are merely wrappers that delegate to a foreign_key object are ignored.

Returns true if field_name is a related_field().

If field_name represents a foreign key or other relationship to a different object class (and hence a different form class), then related_field() will return a hashref with relationship summary information.

If field_name does not represent a related class, will croak.

has_relationship_info( relationship )

Returns true if relationship information is known.

relationship_info( relationship )

Returns the same hashref summary as related_field(), only using a relationship object or name instead of a field name.

Returns the name of a field to use for display from foreign_object_class based on a relationship using field_name.

This magic is best explained via example. Say you have a 'person' object that is related to a 'user' object. The relationship is defined in the 'user' object as:

 person_id => person.id
 

where the id of the 'person' object is a related (foreign key) to the person_id value of the user object. In a form display for the 'user', you might want to display the name of the 'person' rather than the id, so show_related_field_using() will look up the first unique text field in the foreign_object_class (in this case, the 'person' class) and return that field.

 my $field_name = $form->show_related_field_using( 'RDBO::Person', 'person_id' )
 

And because it's a method, you can override show_related_field_using() to perform different logic than simply looking up the first unique text key in the foreign_object_class.

If no matching field is found, returns undef.

foreign_field_value( field_name, rdbo_object )

Returns the value from the foreign object related to rdbo_object for the foreign column related to field_name.

Returns undef if (a) there is no foreign field related to field_name or (b) if there is no foreign object.

Example:

 my $username = $form->foreign_field_value( 'email_address', $person );
 # $username comes from a $user record related to $person

init_yui_datatable_methods

Returns array of method names to use for YUI DataTable columns. Default is field_names().

You may want to override this value, especially for large forms, in order to show only a subset of the most meaningful field values.

AUTHOR

Peter Karman, <karman at cpan.org>

BUGS

Please report any bugs or feature requests to bug-rose-dbx-garden-catalyst at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Rose-DBx-Garden-Catalyst. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Rose::DBx::Garden::Catalyst

You can also look for information at:

ACKNOWLEDGEMENTS

The Minnesota Supercomputing Institute http://www.msi.umn.edu/ sponsored the development of this software.

COPYRIGHT & LICENSE

Copyright 2008 by the Regents of the University of Minnesota.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.