Guest User

Untitled

a guest
Feb 19th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. # WITHOUT cached_models
  2. class Author < ActiveRecord::Base
  3. has_many :posts
  4. has_many :comments, :through => :posts
  5.  
  6. def full_name
  7. @full_name ||= [ first_name, last_name ].join(" ")
  8. end
  9. end
  10.  
  11. class Post < ActiveRecord::Base
  12. belongs_to :author
  13. has_many :comments
  14. has_many :tags, :as => :taggable
  15. end
  16.  
  17. class Comment < ActiveRecord::Base
  18. belongs_to :post
  19. end
  20.  
  21. class Tag < ActiveRecord::Base
  22. belongs_to :taggable, :polymorphic => true
  23. end
  24.  
  25. # WITH cached_models
  26. class CachedAuthor < ActiveRecord::Base
  27. has_many :cached_posts, :cached => true
  28. has_many :cached_comments, :through => :cached_posts, :cached => true
  29.  
  30. def full_name
  31. @full_name ||= [ first_name, last_name ].join(" ")
  32. end
  33. end
  34.  
  35. class CachedPost < ActiveRecord::Base
  36. belongs_to :cached_author, :cached => true
  37. has_many :cached_comments, :cached => true
  38. has_many :cached_tags, :as => :taggable, :cached => true
  39. end
  40.  
  41. class CachedComment < ActiveRecord::Base
  42. belongs_to :cached_post, :cached => true
  43. end
  44.  
  45. class CachedTag < ActiveRecord::Base
  46. belongs_to :taggable, :polymorphic => true, :cached => true
  47. end
Add Comment
Please, Sign In to add comment