[html-formfu] Creating options in many_to_many_select
Jonas Alves
jonas.alves at gmail.com
Sun Dec 16 12:07:34 GMT 2007
On Dec 16, 2007 10:25 AM, Carl Franks <fireartist at gmail.com> wrote:
> On 16/12/2007, Zbigniew Lukasiak <zzbbyy at gmail.com> wrote:
> > Thanks for the explanation. Is it possible to decouple it from
> > Catalyst by putting the schema on the stash?
> > I know FormFu is mostly used with Catalyst - but you never know and
> > beside that it would simplify testing.
>
> Yes, I initially thought it not too dependant on Catalyst - you just
> need an object in $form->stash->{catalyst} that supports a model()
> method - but it makes sense to not have to bother with that.
>
> How about:
> * if db: { model: x } is set, do $db =3D stash->{catalyst}->model(
> args->{db}{model} )
> * else do $db =3D stash->{ args->{db}{stash} }
>
> * and if db: { schema: x } is set, do $db =3D $db->resultset(
> args->{db}{schema} )
>
> This lets you put either your model or table schema on the stash.
>
> Carl
>
This is what I do:
sub get_rs {
my $self =3D shift;
return $self->{_resultset} if $self->{_resultset};
# get stash
my $stash =3D $self->form->stash;
my $rs;
if ( ( my $c =3D $stash->{context} ) && $self->model ) {
$rs =3D $c->model( $self->model )
or croak "\$c->model('@{[$self->model]}') does not exist\n";
}
elsif ( $stash->{schema} && $self->resultset ) {
$rs =3D $stash->{schema}->resultset( $self->resultset )
or croak "Resulset '@{[$self->resultset]}' could not be
loaded.";
}
else {
my $msg
=3D 'need a Catalyst context or a DBIC schema in the stash'
. ' and the respective model or resultset'
. ' parameter in the form config file.';
warn "@{[__PACKAGE__]}: $msg\n";
$self->return_error($msg);
return 0;
}
return $self->{_resultset} =3D $rs;
}
-- =
Jonas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/html-formfu/attachments/20071216/68=
0b7b2f/attachment.htm
More information about the HTML-FormFu
mailing list