On 12 September 2011 13:39,  <ian.doche...@nomura.com> wrote:

> my $response = {
>    foo     = $object->foo,
>    bar     = $object->bar,
>    bam     = $object->bam,
> };
> $c->stash->{ajax_response} = $response;
>
> It should also be possible to create a 'flatten' method that does this for 
> you in a generic manner, you could then have.
>
> $c->stash->{ajax_response} = $object->flatten;

I use a method looking like:

    sub quick_resultset {
        return $_[0]->search_rs(undef, { result_class =>
'DBIx::Class::ResultClass::HashRefInflator' });
    }

in our base result set class ("use Moose; extends
'DBIx::Class::ResultSet';"), so it's available for any result set we
get from our model; then you'd just go

    my $object = $c->model('MyModel::Foo')->quick_resultset->find($object_id);

You may want to call it something different :)

_______________________________________________
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/

Reply via email to