For example, if you run all, the character User Load
appears.
User.all
User Load (3.5ms) SELECT "users".* FROM "users"
On the other hand, when you run pluck
, SQL itself seems to be the same, but User Load
is not displayed.
User.pluck(:name)
(1.9ms) SELECT "users". "name" FROM "users"
At first, I thought it was the difference between loading it into memory, but
I think loading pluck
into memory is the same, so I wondered what the difference was.
names=User.pluck(:name)
(1.9ms) SELECT "users". "name" FROM "users"
names
=>["foo", "bar" ]
If anyone knows the difference between XXX Load
and as shown above, could you please let me know?
The difference between whether the User
object is created or not as a result of the query.(I'm sure)
Rails is based on using model objects, but #pluck
does not create model objects, so it is fast when you simply want a value.
© 2024 OneMinuteCode. All rights reserved.