ActiveRecordã§é ãæ¤ç´¢ãã(ã¡ã¿ãããã°ã©ãã³ã°)
渡ãããè¤æ°ã®idã§æ¤ç´¢ããå¿ è¦ãããæã
@users = User.find(params[:ids].split(/,/))
ã§æ¤ç´¢ãã¡ãé§ç®ã ãï¼æ©ããªã£ã¡ãããããï¼
@users = [] params[:ids].split(/,/).each do |id| @users << User.find(id) end
ã£ã¦æ¤ç´¢ããããï¼idã®æ°ã ãæ¤ç´¢ãã¦ã100ãã©ã¡ã¼ã¿æ¸¡ãæ§ãªå¥´ã ã¨ã
ä¿¡ããããªãé度ããåºã¦ããããããï¼
Userãã¼ãã«ã«é¢é£ããDiaryãã¼ãã«ãæ¤ç´¢ããæã
modelã«has_manyãbelongs_toãå®ç¾©ãã¦
@user = User.find(:all, :include => :diaries)
ã£ã¦ä¸åº¦ã«åã£ã¦æ¥ã¡ãé§ç®ã ãï¼SQLãã¾ã¨ã¾ã£ã¡ããï¼
@diaries @user = User.find(:all) @user.each do | user | @diaries << [user, Diary.find(:all, :conditions => ["user_id = ?", user.id]) ] end
ã£ã¦åã£ã¦ããã¨SQLããã£ã±ãçºè¡ããã¦éãåºæ¥ããï¼
ã¡ããã¨userã¨ã»ããã«ãã¦ãã®ã§ãããã¯ã©ã®ã¦ã¼ã¶ã¼ã®ãã¼ã¿ãå¾ã§æä½ãåºæ¥ããã ï¼
koolã ãï¼
ãããä»è©±é¡ã®ã¡ã¿ãããã°ã©ãã³ã°ã ãï¼
ä»èããåèªã ãã©ï¼