Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActiveRecord 4.2 boolean in string column behavior change #17571

Closed
dnrce opened this issue Nov 10, 2014 · 3 comments
Closed

ActiveRecord 4.2 boolean in string column behavior change #17571

dnrce opened this issue Nov 10, 2014 · 3 comments
Assignees
Milestone

Comments

@dnrce
Copy link
Contributor

dnrce commented Nov 10, 2014

The behavior of true and false in string columns has changed from ActiveRecord 4.1 to 4.2. Previously, the booleans true and false would be stored as t and f, but now they are stored as 1 and 0. Is this an intended change? I don't see it mentioned in the changelog.

Here is a gist which passes using ActiveRecord 4.1.7 but fails with 4.2.0.beta4: https://gist.github.com/dnrce/fd069844ea1b135bcd37

@sgrif sgrif added this to the 4.2.0 milestone Nov 10, 2014
@sgrif sgrif self-assigned this Nov 10, 2014
@sgrif
Copy link
Contributor

sgrif commented Nov 10, 2014

Thanks for the report. This has been fixed.

@sgrif
Copy link
Contributor

sgrif commented Nov 10, 2014

And I don't know how to Github tonight apparently. Fixed by 52c3a16

@sgrif sgrif closed this as completed Nov 10, 2014
sgrif added a commit that referenced this issue Nov 10, 2014
Why are people assigning booleans to string columns? >_>

We unintentionally changed the behavior on Sqlite3 and PostgreSQL.
Boolean values should cast to the database's representation of true and
false. This is 't' and 'f' by default, and "1" and "0" on Mysql. The
implementation to make the connection adapter specific behavior is hacky
at best, and should be re-visted once we decide how we actually want to
separate the concerns related to things that should change based on the
database adapter.

That said, this isn't something I'd expect to change based on my
database adapter. We're storing a string, so the way the database
represents a boolean should be irrelevant. It also seems strange for us
to give booleans special behavior at all in string columns. Why is
`to_s` not sufficient? It's inconsistent and confusing. Perhaps we
should consider deprecating in the future.

Fixes #17571
@dnrce
Copy link
Contributor Author

dnrce commented Nov 10, 2014

@sgrif Agreed it's not the best usage, but thanks for the speedy fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants