mysql - What's the difference between Rails active record's select and group? -
i've been reading through tutorials on rails' active record model operations. , i'm little confused on difference between .select , .group. if wanted names of users in table user believe do:
myusers = user.select(:name)
so how different saying:
myusers = user.group(:name)
thanks,
will
the 2 differ this:
user.select(:name)
is equivalent sql statement
select name users;
and
user.group(:name)
is equivalent to
select * users grouping name;
the difference select(:name)
taking rows ordered id
, column name
. group(:name)
taking rows and columns, ordered column name
.
user.pluck(:name)
fastest way pull names db.
mysql ruby-on-rails rails-activerecord
No comments:
Post a Comment