gurge.com

How to write to the db 27,000 times in 24 seconds instead of 9 minutes.

When you eagerly load an association list using the .include option, and at the same time have a .where on...

snippets.dzone.com

These two models can be used to access the posts and associated comments of a WordPress database.

Deadlocks only occur if two transactions in separate threads compete for the same rows in the database. They usually (but...

If you need to do calculations inside the database and can not use Ruby objects you may run into problems...

When a has_many association basically serves to store a list of associated strings (tags, categories, ...), it can be convenient...

Note that this card is very old. You might want to use ActiveType for your auto-coerced virtual attributes instead...

Don't insert table rows in a Rails database migration. This will break tests that expect that database to be...

Occasionally some complex query must be processed on the database because building thousands of Ruby objects is impracticable.

When you use will_paginage to paginate a scope, and you want to obtain the total number of records matched...

To only run the next two migrations: rake db:migrate STEP=2 To revert the previous two migrations:

Use this scope: class Stick named_scope :shuffled, lambda { last_record = last { :conditions => [ 'id >= ?', rand(last_record.id) ] } if last_record }

CONCAT('foo', 'bar', NULL) = NULL the NULL always wins in MySQL. If you would rather treat NULL as...

Use this MySQL command to show further info about a table: SHOW CREATE TABLE tags; This will output a table...

apidock.com

You can now add an :inverse_of option to has_one, has_many and belongs_to associations.... Without :inverse_of...

When you do tags with acts-as-taggable-on and want to preload associated tags, you can do so with...

If you want to see how long your database queries actually take, you need to disable MySQL's query cache...

It can be useful to have a Ruby expression like condition ? positive_case : negative_case in MySQL queries:

makandra dev
ruby-doc.org

[ ] [ ]= ** ! ~ + - * / % + - >> << & ^ | <= < > >= <=> == === != =~ !~ && || .. ... ? : = %= { /= -= += |= &= >>= <<= *= &&= ||= **= defined? not or and if unless while until begin/end For more information see Table 18.4 in The Pragmatic Programmer's...

These steps are now part of Spreewald. This note describes a Cucumber step that lets you write this:

When you need to delete rows from a table, and the delete conditions require a joined table, MySQL needs to...

You can use record.send(:update_without_callbacks) or record.send(:create_without_callbacks) This can be used as a...

For some reason you want to define a find condition in array form. And in that condition both column name...

Find conditions for scopes can be given either as an array (:conditions => ['state = ?', 'draft']) or a hash (:conditions => { 'state' => 'draft...