"array cannot contain ActiveRecord objects" -- Where is this stated? #870
Replies: 1 comment 1 reply
-
It's a safeguard in The idea is to catch when one loads Active Record objects and puts them in an Array, because once deployed to production that may lead to loading a few million records and that usually fails at some point. Ideally you would express the array as a Relation directly, but as a workaround, if you know you're dealing with relatively few records, you can usually make a new relation, e.g.: def collection
SomeRecord.where(id: array_of_records.map(&:id))
end Feel free to contribute documentation around this. 🙏 |
Beta Was this translation helpful? Give feedback.
-
👋 Hello all. I just recently wrote a task that iterates over an array, and to my surprised it errored out in production with the error "array cannot contain ActiveRecord objects". My question is, where in the documentation is this stated? I see in the README it states:
But I'm not seeing a note that an Array must not contain any AR objects. Am I over looking this somewhere in the documentation?
Beta Was this translation helpful? Give feedback.
All reactions