I have a table of employees with the fields “last_name” and
“first_name”. I would like to populate a collection select so that what
the user sees in the drop-down is “Last Name, First Name”. So far, the
only way I have figured out to do this is by using “find_by_sql” in my
model, like so:
@employees.find_by_sql(“SELECT id, concat(last_name, ', ', first_name)
AS full_name FROM employees ORDER BY full_name”)
It works fine, but someone on the irc said they thought this was the
“dirty” way to go. Any suggestions on a better way to do this?
AWDWR covers this very nicely - it’s called Aggregations.
Right on. Thanks! AWDWR Page 247. I appreciate your pointing me to the
book instead of simply saying “do this.” I’ll learn more this way.
Part of the “problem” with Rails is all the unfamiliar terminology.
That’s not a criticism. It’s just difficult sometimes to know the right
words to use when searching for answers. Fortunately, there seems to be
kind, knowlegable, and growing community.
On Fri, 2006-03-17 at 03:25 +0100, Bob Boyken wrote:
Craig W. wrote:
AWDWR covers this very nicely - it’s called Aggregations.
Right on. Thanks! AWDWR Page 247. I appreciate your pointing me to the
book instead of simply saying “do this.” I’ll learn more this way.
probably - but I may not have done you any favors as the implementation
of aggregations can be difficult in certain areas and when I asked about
it’s usage 6 weeks ago when I started…Bob S. suggested that I just
put the the aggregate name into the table anyway and there have been
many times, I wished I did that. For example, ‘validations’ on an
aggregation are not simple…searching on aggregations is never as
simple. Beware of what you wish for For the record, I’m still
hanging in there with them but they have cost me some large amounts of
time to implement methodologies where a column would have been very
easy.
Part of the “problem” with Rails is all the unfamiliar terminology.
That’s not a criticism. It’s just difficult sometimes to know the right
words to use when searching for answers. Fortunately, there seems to be
kind, knowlegable, and growing community.
I believe I expressed something similar just two days ago (terminology)
and I still am not always certain about brackets, curly brackets and
parens…which to use when/why.