Article / November 5, 2009

batch finding composite primary keys [SOLVED]

By Max Murphy/363 Views/0 Comments

Issue with composite_primary_keys and find_in_batches. In short, they don't play nicely together.

Issue:

Rails 2.3+ find_in_batches will not work if your model has composite primary keys.

Solution:

I found this gist:
https://gist.github.com/105318/13fe7c42c95c820fadbad84d54e00680ce9d110f
which solved the issue. I just dropped it into a file in RAILS_ROOT/config/initializers to extend active record to be able to do batch finds on those models which use composite_primary_keys

Comments

Interesting post?  Show some love and post a comment!
Using pieces of this code?  Post a link!

Add a Comment