Last active
December 26, 2015 13:09
-
-
Save michiels/7155889 to your computer and use it in GitHub Desktop.
This file contains 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 Organization | |
has_many :organization_histories | |
history_methods = [ | |
:coc_number, | |
:coc_office | |
] | |
history_methods.each do |method| | |
define_method(method) do | |
if self.organization_histories.any? | |
# Select the last known organization_history object from the DB | |
self.organization_histories.order("active_from DESC").limit(1).first.call(method) | |
# No related organization_history models. Get the coc_number from the organization model | |
else | |
read_attribute(method) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment