Reputation: 1596
I'm having issues using the groupby and distinct queries in RoR3.
If I using this in my controller, all is well:
@radgroupchecks = Radgroupcheck.find_by_sql("select * from radgroupcheck group by groupname")
But I want to do in rails. I've tried:
@radgroupchecks = Radgroupcheck.select("DISTINCT(groupname)").all
But that gives me an error: wrong number of arguments(1 for 0)
What am I doing wrong?!
Upvotes: 1
Views: 1124
Reputation: 47913
You need to use the group
method for grouping in ActiveRecord. I think what you want is this:
Radgroupcheck.all.group('groupname')
Check out this link for more information.
BTW, it's better (more conventional, but not necessary) to use camel casing for your classes in Ruby (e.g. RedGroupCheck
).
UPDATE: DataMapper
I haven't used DataMapper before, but looks like you need to write something like this:
Redgroupcheck.all(:fields => [:groupname], :unique => true)
This might help. (Search for "group" on that page).
Upvotes: 1