Giter Site home page Giter Site logo

`ActiveHash::Relation` returned by `ActiveHash#where` should be reported like as an array of `ActiveHash` items selected by `where` method, in Rails Console. about active_hash HOT 3 CLOSED

gento-ogane avatar gento-ogane commented on July 16, 2024
`ActiveHash::Relation` returned by `ActiveHash#where` should be reported like as an array of `ActiveHash` items selected by `where` method, in Rails Console.

from active_hash.

Comments (3)

kbrock avatar kbrock commented on July 16, 2024
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.

from active_hash.

flavorjones avatar flavorjones commented on July 16, 2024

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!

from active_hash.

flavorjones avatar flavorjones commented on July 16, 2024

See #288

from active_hash.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.