Stashed $results object throws error on $results->hash in template
ViktorNacht opened this issue · comments
Not sure if this is a bug in Mojo::mysql, Mojolicious, or expected behavior due to my ignorance of how the stash works. But when I get a simple results object like this:
my $results = $c->mysql->db->select(widgets => '' => { color => 'blue' });
and then stash it:
$c->stash(results => $results);
and then try to call $results->hash
on it from a template:
% while (my $foo = $widgets->hash) {
%# Do stuff
% }
I get the error message below. I know how to work around it by using $results->hashes->to_array
and pass that result to the stash, but I'd like to have the full power of the module inside of templates. Any thoughts?
The results object is just a wrapper around the statement handle. It's possible you'll lose the connection before the template renders. My recommendation would be to avoid the problem and keep the results fetching out of the template.
Mojo::mysql::Results may also need this change, though I don't remember exactly the reasoning. mojolicious/mojo-pg@fa47254#diff-ebed6d285154b1c54f7957a4e94cbf6c
The results object is just a wrapper around the statement handle. It's possible you'll lose the connection before the template renders.
Ah ha.. thank you for the reply. FYI I'm using it in an under
block, which might even be complicating things more. I think it's unfortunate, but I understand the issue.