On Mon, Mar 16, 2009 at 10:53 AM, Moritz Onken <[email protected]>wrote:

>
>> Hi Scott,
>>
>> thank for your reply, in having a go at using Catalyst::View::JSON i keep
>> running into the
>>
>> "... encountered object 'MyApp::Model::DB::Experiment=HASH(0xe8ac4c)', but
>> neither allow_blessed nor convert_blessed settings ... "
>>
>> error. I'm getting data from DBIC but can't figure out how to get that
>> into Catalyst::View::JSON. The "hello world" example works fine, but when
>> trying to adapt this i run into trouble
>>
>> sub hello : Local {
>>     my($self, $c) = @_;
>> #      $c->stash->{message} = 'Hello World!';
>>
>>     $c->stash->{books} = [$c->model('DB::Books')->all];  ### this doesn't
>> work....
>>
>>     $c->forward('MyApp::View::JSON');
>> }
>>
>> any pointers into the right syntax/approach here would be greatly
>> appreciated. I presume i have to write some kind of JSON encoder for the
>> data coming out of $c->model('DB::Books')->all?
>>
>> thanks again for your help
>>
>
>
> Hi,
>
>
> You can access the raw data through $row->{_column_data}. But this is not
> recommended because it doesn't call any inflators.
>
> try
>
>  $c->stash->{books} = [map { $_->{_column_data} }
>> $c->model('DB::Books')->all];
>>
>
>
>
> Moritz
>
>
>
No, don't do that!

Use $row->get_columns which returns a hash of the column data!  Accessing
internal methods is bad, accessing internal hash keys is doubleplusungood.
If you find yourself doing that, go read some documentation.  If you haven't
figured it out without doing that, submit a patch for a proper method!

Here's the pod:
http://search.cpan.org/~ribasushi/DBIx-Class-0.08012/lib/DBIx/Class/Row.pm#get_columns

Also, you can use the HashRefInflator which works -fantastic- for JSON
views:

The code is very simple:

my $rs = $c->model('DB::Books');
$rs->resultclass('DBIx::Class::HashRefInflator');
$c->stash->{books} = [ $rs->all ];

You can read about that here:
http://search.cpan.org/~ash/DBIx-Class-0.08010/lib/DBIx/Class/ResultClass/HashRefInflator.pm

-Jay

-- 
J. Shirley :: [email protected] :: Killing two stones with one bird...
http://www.toeat.com
_______________________________________________
List: [email protected]
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/

Reply via email to