Created
May 19, 2014 16:18
-
-
Save thehenster/183c3efefa6343895452 to your computer and use it in GitHub Desktop.
Delegation of class methods through an association..
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 Event < ActiveRecord::Base | |
has_many :artists | |
end | |
class Artist < ActiveRecord::Base | |
def self.make_me_an_artist | |
create! do |artist| | |
artist.cached_event_time = artist.event.time | |
end | |
end | |
end | |
event = Event.create(time: "3pm") | |
event.artists.make_me_an_artist | |
event.artists.first.cached_event_time #=> "3pm" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment