Prev | Current Page 230 | Next

David Berube

"Practical Reporting with Ruby and Rails"

Notice that, unlike the previous approach, this query
excludes users who are not eligible for a reward. The reason this query is so complicated is because
the relationship between the rewards table and the users table has a grouping function in it, which
cannot appear in a join condition. If you could use counter caching, you could do a simpler version of
this query. The counter-caching version would look something like this:
users = User.find_by_sql("
SELECT users.*
COALESCE(rewards_1.description, '') as reward_description
FROM users
INNER JOIN
rewards as rewards_1
ON rewards_1.meeting_count <
users.meeting_count
AND NOT EXISTS (
SELECT *
FROM rewards as rewards_2
WHERE (rewards_2.meeting_count <
users.meeting_count)
AND
(rewards_2.meeting_count >
rewards_1.meeting_count))
ORDER BY last_name ASC, first_name ASC
;")
After you have finished creating your HTML, you need to run it through two successive
programs. First, you put it through html2ps, as follows:
ps_source = ''
open('|"'+path_to_html2ps+'"', 'wb+') do |process_handle|
process_handle.


Pages:
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
Kwiaty doniczkowe kurs do matury Stomatolog Catering Warszawa bilety lotnicze