0

I'm using DataMapper as ORM framework after many years of experience with AR. For that reason I sometimes try to find a specific DM function that mirrors some behaviour from AR. Sometimes I'm lucky, sometimes I'm not. With the #reload directive, I'm kind of in a limbo. The method exists, but somehow doesn't do what I expected it to. Basically, instead of the AR behaviour in which the instance attributes would be updated looking up to the DB, DM somehow marks every attributes from the instance as "not loaded".

Can somebody tell me if this is possible to achieve using DM?

ChuckE
  • 5,040
  • 2
  • 27
  • 54

1 Answers1

1

DataMapper marks the attributes as not loaded and will load them on the next access.

This is a result from support of lazy loading groups. DM-1 will wait to see what attribute is accessed next to load only a limited set of attributes.

Per default all attributes are in the :default group, so most likely all attributes are loaded once you hit one.

In case this lazy behavior is not wanted you can do the following:

resource = YourClass.first(:some => :stuff)
# full non lazy reload (make sure you do not have 
# a reference to old somewhere that causes confusion
resource = resource.model.get(resource.id)
mbj
  • 1,032
  • 9
  • 19