Hello, friends in my last post I described how to fetch with pluck and select,
Today I am going to show you what exact difference between them.
In below screenshot, I have 3 different user record, which we are fetching with different queries.
Today I am going to show you what exact difference between them.
In below screenshot, I have 3 different user record, which we are fetching with different queries.
=> User.all.select(:email)
select takes (0.3ms) when find user by email and returns Active record object.
select takes (0.3ms) when find user by email and returns Active record object.
=> User.all.pluck(:email)
pluck also takes (0.3ms) when find user by email and returns email Array.
pluck also takes (0.3ms) when find user by email and returns email Array.
=> User.all.collect(&:email)
collect takes (0.4ms) when find user by email and returns email Array.
collect takes (0.4ms) when find user by email and returns email Array.
=> User.all.map(&:email)
map takes (0.5ms) when find user by email and returns email Array.
You can also test it on your rails console.
You can also test it on your rails console.
No comments:
Post a Comment