[Catalyst] $c->user->some_relationship always retrives user
id from the db
Moritz Onken
onken at houseofdesign.de
Thu Feb 14 08:14:04 GMT 2008
Am 14.02.2008 um 00:11 schrieb Jay K:
> Hi there Moritz,
>
> The select by id that you are seeing is the retrieval of the user from
> the database when first recovering the user from the session. I am
> assuming that you are using the
> Catalyst::Authentication::Store::DBIx::Class storage module. Any
> access to $c->user will trigger this query. It is, however, only done
> once per request.
>
> In short - if you are going to be using $c->user in any way during the
> request, that find by id will be done at some point. So going out of
> your way to avoid it only makes sense if you are sure you will not use
> any other user information during the request.
>
> Jay
So why do I need to recovery the whole user row for every request?
I could use
$user_id = $c->session->{user_id};
@albums = $c->model('albums')->search({ user_id => $user_id });
as Mitchell suggested but I'd prefer to fetch the data by using $c-
>user because its the way one should do it.
might it be possible to store the user row in the session at login and
recover $c->user from the session on every request?
I know this might break if I change something in the user row.
moritz
More information about the Catalyst
mailing list