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

Form::Processor::Model::RDBO - Model class for Form Processor using Rose::DB::Object

SYNOPSIS

Same API as in Form::Processor::Model::DBIC. For more documentation and examples see it. Here are written only Rose::DB::Object special cases.

METHODS

manager_module

Defines the default name for Rose::DB::Object managers. You are free to override this property if the name of your Manager module differs.

init_item

This is called on the first call of $form->item. It also validates that the item id matches /^\d+$/. Override this method in your form class (or form base class) if your ids do not match that pattern.

init_value

Populate $field->value with object ids from the Rose::DB::Object object. If the column expands to more than one object then an array ref is set.

guess_field_type

Tries to guess field type of the passed column. Currently only looks at RDBO relationships. And returns the type 'Select' for 'one to one' or 'many to one' relations and 'Text' in other cases.

lookup_options

Tries to get options for the filed, derived from Form::Processor::Field::Select (e.g. Select and Multiple) from the database. First, it asks foreign RDBO class if it can 'active_column'. Active columns is used for labeling select fields.

package Schema::RDBO::Current;
use strict;
use base qw(DB::Object);
__PACKAGE__->meta->setup(
  foreign_keys =>
  [
    foreign_fk => {
      class => 'RDBO::ForeignTable'
    }
  ]
);
1;

package Schema::RDBO::ForeignTable;
use strict;
use base qw(DB::Object);
__PACKAGE__->meta->setup(
  columns => [
    qw/ id title  /
  ],
);

sub active_column { 'title' }

1;

Value returned by active_column method is used in building sql. If not defined it will be set to the default 'name'. If you want to have freedom how to set up label and active_column is not enough, you can declare active_column_method method that is called when labeling value as a method of retreived object.

sub active_column_method {
  ucfirst $_[0]->title;
}

If no active_column method was found it gets default 'name' value. If active column exists in the foreign RDBO schema class, reference to array of key/value pairs will be returned and the options for field will be filled automatically. Otherwise it will return the empty array.

update_from_form

Makes form validation and returns the filled RDBO item, filled by update_model. It does not save the current item automatically. You should do this in your code, after the call update_from_form.

update_model

Returns the new RDBO item, filled with passed form params. It does not save any data to the database, just creates and fills new RDBO object.

model_validate

Does simple validation of fields, that you specified as unique in your form profile. You are free to override this method if you want to implement much serious model validation.

validate_unique

Internal method. Does simple validation of fields, that you specified as unique in your form profile.

items_same

Internal method. Compares two RDBO items. Returns true, if the items are same.

primary_key

Internal method. Returns the primary key of items. Joins compound primary key in one string value. Used in method items_same.

AUTHORS

vti <vti@cpan.org>; 
dzhariy <dzhariy@cpan.org>

CONTRIBUTORS

Form::Processor::Model::CDBI written by Bill Moseley; Form::Processor::Model::DBIC ( Gerda Shank )

A big part of code and documentation from those two modules is adapted and used for current Form::Processor::Model::RDBO.

LICENSE

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

SEE ALSO

Form::Processor Form::Processor::Model::CDBI Form::Processor::Model::DBIC Catalyst::Plugin::Form::Processor Rose::Object Rose::DB::Object Rose::DB::Object::Tutorial