I think that example 4 on the grayproductions website is a pretty good
example of when you might want to do this. We use that technique in
some reports already, and it makes a lot of sense there - why not just
ask the db for all the data you want at once?
I have a few concerns though:
- is all the logic about what it means to be "viewed" tied up in
that select? Do we have to duplicate it in a scope? What if we want to
get some_profile.viewed.last ?
- what if we only want 1 of those counts at a time? Or all of them,
plus some more?
I know those issues can be worked around, but the workarounds I can
think of seem kind of clunky.
When James and I first talked about this, I thought he was suggesting
adding a select as a default scope to a model, then using that to
replace a normal method (including the view count every single time we
loaded a profile, or something similar). So my initial impression is
that you were looking for semi-permanent attributes rather than
temporary. Sorry about the mixup.
I still think that kind of default scope stuff would would be
trickiness without a real payoff, but if it's a one-off, :select makes
sense.