Forum: Ruby on Rails [rails 4.1] weird behaviour in rails console? lazy loading of database connection or spring?

Ac1285df11444a2e9dc5274d78f88187?d=identicon&s=25 nathanvda (Guest)
on 2014-04-23 16:02
(Received via mailing list)
I guess I am the only one using it like this, by i regularly start my
`rails console` to quickly show the column-names of models.

Since 4.1 (afaik), the first call to a class does not return the model
introspection, but instead urges me to use `Batch.connection` to
establish
a connection???

If I use a specific method to get the column names, I get no error, and
afterwards the class introspection just works.

Of course this is no biggie, but I am curious what the cause is of the
this
behaviour, whether this is intended or not, and how I could circumvent
it.

Example console output:

```
Loading development environment (Rails 4.1.0)
 :001 > Batch
 => Batch (call 'Batch.connection' to establish a connection)
 :002 > Batch.column_names
 => ["id", "name", "batch_nr", "revision", "comments",
"batch_status_id",
"created_at", "updated_at"]
 :003 > Batch
 => Batch(id: integer, name: string, batch_nr: string, revision: string,
comments: text, batch_status_id: integer, created_at: datetime,
updated_at:
datetime)
```

Any tips or hints would be greatly appreciated.
Bee69cfed999cd13e3bff73d472a39ee?d=identicon&s=25 Hassan Schroeder (Guest)
on 2014-04-23 17:46
(Received via mailing list)
On Wed, Apr 23, 2014 at 7:01 AM, nathanvda <nathanvda@gmail.com> wrote:

> Since 4.1 (afaik), the first call to a class does not return the model
> introspection, but instead urges me to use `Batch.connection` to establish a
> connection???

> Of course this is no biggie, but I am curious what the cause is of the this
> behaviour, whether this is intended or not, and how I could circumvent it.

I've noticed that, and it seems like a bug to me, but I haven't had the
time to investigate.

That said, this behavior doesn't occur when using `pry` for the Rails
console, so just one more reason to make that standard :-)

FWIW,
--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
http://about.me/hassanschroeder
twitter: @hassan
E70898f37849dbf229c702fdaf88962f?d=identicon&s=25 Makis Giaourtis (gtx507)
on 2014-09-18 12:37
I got the same behaviour in Rails 4.0.8
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.