Closed gento-ogane closed 1 year ago
Model.limit(3).class
=> Vm::ActiveRecord_Relation
byebug ; pp Model.limit(3)
# byebug ; Model.limit(3)
# s
# up
# s
# up
[598, 607] in /Users/kbrock/.rubies/ruby-3.0.6/lib/ruby/3.0.0/pp.rb
598:
599: # prints arguments in pretty form.
600: #
601: # pp returns argument(s).
602: def pp(*objs)
=> 603: objs.each {|obj|
604: PP.pp(obj)
605: }
606: objs.size <= 1 ? objs.first : objs
607: end
(byebug) objs.class
Array
That has me confused. Not sure why this would be an array and not a relation class Sorry I don't have the bandwidth to go further.
What's going on here is that IRB's REPL loop runs pp
to print the previous line's value.
We can customize the pp
output for Active Hash associations by implementing a #pretty_print
method as documented in PP Output Customization.
I'll give it a try!
See #288
summary
ActiveHash::Relation
returned byActiveHash#where
should be reported like as an array ofActiveHash
items selected bywhere
method, in Rails Console. BecauseActiveRecord::Relation
returned byActiveRecord#where
is reported like as an array ofActiveRecord
instances selected bywhere
method, in Rails Console.environment
Steps to reproduce
actual result
expected result
additional information
Now I'm trying to fix this problem. I'm researching which is the code should be modified: activehash, rails console, or irb itself.