#1317 ✓resolved

belongs_to bypasses the identity map cache

Reported by gioele | June 12th, 2010 @ 11:23 AM | in 1.1

From #datamapper

belongs_to relationships don't use get under the hood.

This means that the cache provided by identity map is bypassed with a big hit on performance.

In this example

class Store
    property :address

class Product
    property :location

    belongs_to :store

    # XXX: this method makes one SQL query for each invocation
    def in_original_store?
        location == store.address

calling Product#in_original_store? a thousand times will generate a thousand queries, even when there are only two or three Store objects stored in the whole repository.

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »