On Mar 27, 2017 7:19 PM, "james foss" <[email protected]> wrote:

Hi,

I'm trying to get m head around growing Lite to full apps.  I'm using DBIx
Class and I have a query in my controller that I think should be moved to a
model.  My query works fine in a controller but when I move it to a model I
get a 'cannot locate object method db in package App::Model::Name' error -
I am using a db helper set in entry module.  Instead of running the code
from the controller I wanted o call something like
App::Model::Name->select, is this the wrong approach?

I have tried adding has 'db' to the model and accessing it via a helper:
self->helper(model => sub { state $model = App::Model::Name->new}) but
neither of these work.  As I say I am still learning but could someone help
me out please?


I think you need to pass the db to your helper.

$self->helper(model => sub { state $model = App::Model::Name->new(db =>
shift->db) });

-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

Reply via email to