开发者

conditions without repeats

开发者 https://www.devze.com 2022-12-31 17:31 出处:网络
Hi i\'m using this for getting data: Topic.find(:all, :include => ..., :conditions => @core ? [\"cores_topics.id = ? AND visible = 1 AND (distance < ? OR cores.id IN (?))\",@core.id, @user_l

Hi i'm using this for getting data:

Topic.find(:all, :include => ...,
:conditions => @core ? ["cores_topics.id = ? AND visible = 1 AND (distance < ? OR cores.id IN (?))",@core.id, @user_location[3].to_i, @user_friends] : 
["visible = 1 AND (distance < ? OR cores.id IN (?))", @user_location[3].to_i, @user_friends], 
...

how can i rewrite the conditions sh开发者_开发问答orter?


how can i rewrite the conditions shorter?

User smaller variable names.

OK, really. Read the docs for named_scope. Your code is crying out for them.

0

精彩评论

暂无评论...
验证码 换一张
取 消