[html-formfu] model-dbic update - nested_base accessors
Carl Franks
fireartist at gmail.com
Fri Jul 11 15:40:00 BST 2008
I've committed some changes to HTML-FormFu-Model-DBIC which allow you
to define a Block, that uses nested_base to point to a ResultSource
accessor which isn't a column or relationship.
For example, in my 'Groups' result-source, I have a column1 method, like so:
sub column1 {
my ($self) = @_;
my $content = $self->find_or_new_related( 'content', { region
=> 'column1' } );
if ( @_ > 1 ) {
$content->update(@_);
}
return $content;
}
This allows me to do
$group->column1;
instead of
$group->find_related( 'content', { region => 'column1' } );
In my group-editing form, I can now do this:
---
elements:
- name: group_name
- type: Block
nested_name: column1
model_config:
nested_base: column1
elements:
- name: content
So now, both default_values() and update() will use the Block to
follow the related-row, and get/set the 'content' value from that row.
The reason I've added this, is to be able to more flexibly handle
'has_many' relationships, without having to use a Repeatable block.
Hope it might be useful for someone else too...
Cheers,
Carl
More information about the HTML-FormFu
mailing list