On Monday, November 23, 2015 at 5:02:34 AM UTC-8, Sylver wrote:
>
> Hi,
>
> Jeremy, I think we already talked about it, but i can't find where and 
> what you answered me. Maybe it was on IRC.
>
> I have an association dataset with a variable value in it, related to the 
> session, which look like this :
>
>   many_to_many :session_follower, :clone => :followers do |ds|
>     ds.where(:follower_id => $sinatra_session[:user_id])
>   end
>
> The problem is this block is cached when starting the app and the 
> $sinatra_session isn't updated if the value changes.
>
>  How to optimize this, how could I introduce a parameter to pass a fresh 
> session user_id to this dataset ?
>

 many_to_many :session_follower, :clone => :followers do |ds|
    ds.where(:follower_id => Sequel.delay{$sinatra_session[:user_id]})
 end

Note that it's a bad idea to have your model code depend on your web code. 
 A better way to do this would be to do the following in your web code:

obj.followers{|ds| ds.where(:follower_id=>session[:user_id])}

Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" 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/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to