In my model I have three complex scopes returning the Discount object arrays. Each of these can overlap, and I want to do some Ruby array union/intersection/substraction operations.
I guess these operations depend on the object id. I am wondering if Discount queries will return the same record as the same object when it is through different scopes. In my program those will be done during the same request.
UPDATE:
I was wrong, twice. Each objects returned are truly different objects. And though they are different, the union/intersection/substraction operations still works correctly.
By default no – you’ll get two objects representing the same database row. Check the
object_idif you need convincing.In Rails 3.1 and above you can turn on the identity map. This ensures that inside a given request a single row in the database will always be represented by a single ruby object. There are still some kinks in it, which is why it isn’t on by default.