LoginSignup
0
0

More than 3 years have passed since last update.

コンソールで"モデル名.connection"してくれと言われた。

Posted at

"モデル名.connection"でコンソールが汚れないようにするには

カラム名を参照するとき、コンソールでモデル名を入力し確認することが多い。
rails db:resetした後で、いつものようにPostモデルのカラム名を参照しようとしたら、Post.connectionしてくれとのレスが返ってきた。

pry(main)> Post
 => Post (call 'Post.connection' to establish a connection)

言われた通りコンソールでPost.connectionにすると、夥しい量のコードでコンソールが汚れる。

pry(main)> Post.connection
=> #<ActiveRecord::ConnectionAdapters::PostgreSQLAdapter:0x00007fc55bedab20
 @config=  {:adapter=>"postgresql",
   :encoding=>"unicode",
   :pool=>5,   :database=>"beershelf_development"},
 @connection=#<PG::Connection:0x00007fc55beeaa98>, @connection_parameters={:dbname=>"beershelf_development"}, @idle_since=696392.120269,
 @instrumenter=
  #<ActiveSupport::Notifications::Instrumenter:0x00007fc55beb1900
   @id="40e50609520945ffce99",   @notifier=

以下省略

コンソールが汚れないようにするには、.connrction.countにすればいい。

pry(main)> Post.count
   (1.4ms)  SELECT COUNT(*) FROM "posts"
=> 1
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0