[Catalyst] RE: DBIC <-> JSON conversion for AJAX

Ian.Docherty at nomura.com Ian.Docherty at nomura.com
Wed Sep 14 15:12:58 GMT 2011


search calls ->all() implicitly on the resultset in list context so the following should work.

sub thing_GET {
	my ($self, $c) = @_;  
	my @arr = $c->model('DB::data)->search({}, {
   		result_class =>
'DBIx::Class::ResultClass::HashRefInflator',
 	});
	
	$self->status_ok(	
		$c,
		entity => \@arr
	);
}

-----Original Message-----
From: Roland Philibert [mailto:rphilibert at aptina.com] 
Sent: 14 September 2011 15:54
To: The elegant MVC web framework
Subject: RE: [Catalyst] RE: DBIC <-> JSON conversion for AJAX

Eden or anybody familiar on this subject,

I tried your solution (REST + DBIx::..::HashRefInflator) but because my
search retrieve more than one rows, I populated an array as per:

sub thing_GET {

	my ($self, $c) = @_;  
	my @arr=();
	my $rs = $c->model('DB::data)->search({}, {
   		result_class =>
'DBIx::Class::ResultClass::HashRefInflator',
 	});
	
 	while (my $hashref = $rs->next) {
		push @arr,$hashref;
 	}
	
	$self->status_ok(	
		$c,
		entity => \@arr
	);
}



Would you say that this is a valid approach? Or can I retrieve all data
bu other means with the DBIx model?

Thanks
Roland




This e-mail (including any attachments) is confidential, may contain
proprietary or privileged information and is intended for the named
recipient(s) only. Unintended recipients are prohibited from taking action
on the basis of information in this e-mail and must delete all copies.
Nomura will not accept responsibility or liability for the accuracy or
completeness of, or the presence of any virus or disabling code in, this
e-mail. If verification is sought please request a hard copy. Any reference
to the terms of executed transactions should be treated as preliminary only
and subject to formal written confirmation by Nomura. Nomura reserves the
right to monitor e-mail communications through its networks (in accordance
with applicable laws). No confidentiality or privilege is waived or lost by
Nomura by any mistransmission of this e-mail. Any reference to "Nomura" is
a reference to any entity in the Nomura Holdings, Inc. group. Please read
our Electronic Communications Legal Notice which forms part of this e-mail:
http://www.Nomura.com/email_disclaimer.htm




More information about the Catalyst mailing list