First page Back Continue Last page Overview Text

Notes:


Sequel gives you the ability to eagerly load custom associations, using the eager_loader association option.

This option takes a proc that accepts 3 arguments, a key hash, an array of current objects, and the dependent associations to eagerly load.

The key hash is an optimization. It's a hash of hashes were the keys are columns, such as id, and the values are subhashes.

The subhashes have keys which are the values of the column, such as 1 or 2, and values which are an array of instances which have the related value for that column.

So in the example above, firm1 has id 1 and firm2 has id 2.

In this case, since the association depends on the firm's primary key, we only care about that specific subhash, which we assign to a local variable id_map.