Closed TheHumaneClub closed 14 years ago
>> Alert.all(:select => "alertable_id, alertable_type, max(id) as max_id", :conditions => {:project_id => 1 }, :group => "alertable_id, alertable_type", :limit => 10).first.max_id
Alert Load (5.6ms) SELECT alertable_id, alertable_type, max(id) as max_id FROM `alerts` WHERE (`alerts`.`project_id` = 1) GROUP BY alertable_id, alertable_type ORDER BY id desc LIMIT 10
=> "97"
>>
Is it what you wanted?
The idea is to print only the TOP MOST comment of each alertable_type, alertable_id
So I think it should be calculated separately for tasks, wikis, articles, etc.
Dont Agree. Alertable_type and alertable_id is the only UNIQUE way to identity INDIVIDUAL task, wiki, etc
Alertable_type => Article / Asset / Task / WikiPage
What say??
you can't do it in one query anyway
We are using 2 queries already. Check Alerts model. There is self.forproject which is supposed to return alertable_type, alertable_id, max_id Finally, in display we query again Alert.find_by_id(max_id) to get all details of Alerts
clo
This below query works in MYSQL but in Ruby it gives only Alertable_id and Alertable_type in output. Alert.all(:select => "alertable_id, alertable_type, max(id)", :conditions => {:project_id => projectid }, :group => "alertable_id, alertable_type", :limit => count)
Bottom line, presently alerts is working query Alert.all(:conditions => {:project_id => projectid }, :order => "id desc", :limit => count)
Possibly give it to Sergey to correct Query