Created
January 15, 2014 19:41
-
-
Save workmaster2n/8443003 to your computer and use it in GitHub Desktop.
Cacheing has_many through:
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
| p = Person.create | |
| p.items << Item.create | |
| Rails.cache.write(Time.now, p) | |
| => false | |
| p.reload | |
| Rails.cache.write(Time.now, p) | |
| => <truthy> |
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 Item < ActiveRecord::Base | |
| attr_accessible :description | |
| has_many :person_items | |
| has_many :people, through: :person_items | |
| 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 Person < ActiveRecord::Base | |
| attr_accessible :name | |
| has_many :person_locations | |
| has_many :locations, through: :person_locations | |
| has_many :person_items | |
| has_many :items, through: :person_items | |
| 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 PersonItem < ActiveRecord::Base | |
| attr_accessible :item_id, :person_id | |
| belongs_to :item | |
| belongs_to :person | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment