For reasons that completely escape me, MySQL 5.x limits UTF-8 strings to U+FFFF and smaller.
Arel is a library that was introduced in Rails 3 for use in constructing SQL queries. Every time you pass a hash to where, it goes through Arel eventually. Rails exposes this with a public API th…
If you care about performance, never use a query like
UPDATE users SET has_message = 1 WHERE users.id IN (SELECT user_id FROM messages)
MySQL does not optimize this and seems to scan the tempo…
An association defined with
has_many :through will return the same record multiple times if multiple join models for the same record exist. If that isn't what you want, you need to add the `:uniq…
The Edge Rider gem allows you to collect an array of values for one field of your ActiveRecord elements:
>> User.active.collect_column(:id, :conditio...
Rails 4.0 introduced a helpful new method for ActiveRecord queries:
where.not. It can make clunky queries easier to read.
I had a huge MySQL dump that took forever (as in: days) to import, while I actually just wanted to have the full database structure with some data to use on my development machine.
After trying se…
DECIMAL column is used when it is important to preserve exact precision. It takes two parameters, where precision is the total number of digits and scale the number of digit…
CONCAT('foo', 'bar', NULL) = NULL
the NULL always wins.
If you would rather treat NULL as an empty string, use [
TLDR: This card explains which threads and processes interact with each other when you run a Selenium test with Capybara. This will help you understand "impossible" behavior of your tests.
has_many associations with a
:through option can lead to lost or duplicate records. You should avoid them, or only use them to read records.
class User < A...
When MySQL refuses to use your index, you can do a number of things wrong. One of them might be conditions with improper data types.
For example, let's assume you have a
tl;dr: Do not use
merge! for session hashes. Use
Let's assume you're modifying the Rails session. For simplicity, let's also assume your session is empty when you s…
|Cancel later callbacks||
|Rollback the transaction||`return fa…|
This error occurs when you already have a
database.yml which defines the database for the
cucumber environment instead of
database.sample.yml has changed)
Here is a way to create a duplicate of one database, with all its tables and their data, under a new name.
- Make a dump of your source database:
mysqldump -uroot -p my_project -r my_proje...
validates_uniqueness_of is not sufficient to ensure the uniqueness of a value. The reason for this is that in production, multiple worker processes can cause race conditions:
- Two concurrent r…
Usually our mysql queries are not case sensitive. In order to query case sensitive, you can use the mysql COLLATE clause. The collate clause lets you specify a collation, which basically is a s…