Skip to content

Instantly share code, notes, and snippets.

@bernerdschaefer
Created August 3, 2010 18:23
Show Gist options
  • Select an option

  • Save bernerdschaefer/506866 to your computer and use it in GitHub Desktop.

Select an option

Save bernerdschaefer/506866 to your computer and use it in GitHub Desktop.
class User
def doctors=(doctors)
write_attribute(:cached_doctors, doctors.map(&:attributes))
@doctors = doctors
end
def doctors
@doctors ||= read_attribute(:cached_doctors).map do |doctor|
Mongoid::Factory.build(Doctor, doctor)
end
end
end
class CachedDoctors
def self.set(doctors)
doctors.map { |doctor| doctor.attributes }
end
def self.get(doctors)
doctors.map { |doctor| Mongoid::Factory.build(Doctor, doctor) }
end
end
User.field :doctors, :type => CachedDoctors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment