Created
August 3, 2010 18:23
-
-
Save bernerdschaefer/506866 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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