eager loading with userSession.find

40 views
Skip to first unread message

James

unread,
Dec 8, 2010, 6:44:10 AM12/8/10
to Authlogic
i know we can get the current user using userSession.find. I am
wondering if there is a way to do the eager loading for the current
user, which means i can get associated models for the current user
when i look up the current user. I have been messing around with
authlogic but have not figured out how to do that.

Thanks in advance!

James

James

unread,
Dec 8, 2010, 10:07:04 AM12/8/10
to Authlogic
i thought i could re-define find_by_login_method to another method to
do eager loading. But it seems the new method didn't get called.

Here is my code:

class AuserSession < Authlogic::Session::Base
find_by_login_method :find_by_phone
end


class Auser < ActiveRecord::Base

has_one :user

def self.find_by_phone(login)
debugger
find_by_phone(login,:include =>:user)
end


end


Thanks..
James

Leandro Marcucci

unread,
Aug 25, 2011, 5:01:24 PM8/25/11
to auth...@googlegroups.com
Bump this. I have the same necessity.

@james, find_by_login_method was the first place i went to do this, but this method is only called on session creation (when the user logs in).

Aided by debugger I've come to find that the actual user load query is run during the callbacks execution process.

I still have to run an extra query to load user details stored in a different table. Ben, can have solution/advice plz?


Matt Garland

unread,
Sep 2, 2011, 6:42:45 PM9/2/11
to Authlogic
Bump as well. I am trying to return associations via as_json:

class UserSession < Authlogic::Session::Base
def as_json(options={})
super(:include=>{:user=> {:include=>
{:assignments=>{}, :locks=>{} }}})
end
end

but no joy. Maybe I can configure what UserSession returns? Just
wanted to see if I was missing something obvious before I exploring
Authlogic::Session::Base.
Reply all
Reply to author
Forward
0 new messages