First page Back Continue Last page Overview Text


Alright, last query. This one uses a filter with a block.

Inside the block, instance methods without arguments, such as date, refer to SQL columns and instance methods with arguments, such as date_part, refer to SQL functions.

The exclude method operates as an inverse filter. Using a hash with a nil value would generally set up an IS NULL condition, and exclude changes it to IS NOT NULL.

Finally, see how you can reference existing columns when setting new values, which is how the new value of price can depend on the existing price.

This is powerful as it allows you to update prices for all filtered records at once, instead of retrieving all filtered records, determining what the new price should be, and updating each record individually.

When possible, you should attempt to update multiple records in a single query unless you have a good reason not to.