Hi all,
I am using Rose::DB::Object in combination with Mojo.
I have hit on an issue, though for the simple case I also have a
workaround. The point is that in a Mojo .ep template, the call of a
method, generated (I guess) from a defined 'relationship', does not
work. To be more precise, the call only seems to work if before the
rendering of the template the same method is called in the calling
controller.
In the code snippets below the problematic method is movies().
So how should we use (or not use) these pseudo-methods of Rose::* in
Mojo's .ep templates?

In the User model, a relationship 'movies' is defined
    #User.pm
    use base qw(MyApp::DB::Object);
    __PACKAGE__->meta->setup (
      table      => 'users',
      unique_key => ['user_name'],
      auto       => 1,
      relationships =>
      [ movies =>
         {
           type         => 'many to many',
           map_class    => 'MyApp::Models::UserMovie',
           manager_args => { with_map_records => 1 },
         },
       ]

In the controller, it seems the call $u->movies is needed;
   #UserController.pm
   my $u = 'MyApp::Models::User'->new(user_name => $user_name);
   $u->load;
   $u->movies;   #needed !?
   $shift->stash( user_obj => $u );
   #render template

In the template, ->movies is called but only works if same call is
done in controller first.
   #template.html.ep
   % foreach( @{$user_obj->movies} ) {      #works only if $u->movies
called in controller.
       ....
   % }

Regards,
Henk

-- 
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 http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

Reply via email to