Your SlideShare is downloading. ×
ActiveRecord Associations (1), Season 1
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

ActiveRecord Associations (1), Season 1

4,271
views

Published on

제7차 ROR Lab. 강의록

제7차 ROR Lab. 강의록

Published in: Education, Technology, Business

1 Comment
3 Likes
Statistics
Notes
  • http://www.slideshare.net/hyoseongchoi/activerecord-associations-2
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
4,271
On Slideshare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
34
Comments
1
Likes
3
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Transcript

    • 1. The 7th Round of ROR Lab.Active RecordAssociations - 1 February 18th, 2012 Hyoseong Choi ROR Lab.
    • 2. For what? ROR Lab.
    • 3. For what?To add an order ROR Lab.
    • 4. For what?To add an order ROR Lab.
    • 5. For what?To add an orderTo delete orders ROR Lab.
    • 6. For what?To add an orderTo delete orders ROR Lab.
    • 7. For what?• Automation of connecting btw models• Automatic assignment of foreign key ROR Lab.
    • 8. For what? Primary & Foreign Keyscustomer order id id ROR Lab.
    • 9. For what? Primary & Foreign Keyscustomer order id id customer_idparent obj. child obj. ROR Lab.
    • 10. For what? Primary & Foreign Keyscustomer order id id Active Record customer_id Assocationparent obj. child obj. ROR Lab.
    • 11. For what? ROR Lab.
    • 12. For what?To add an order ROR Lab.
    • 13. For what?To add an order ROR Lab.
    • 14. For what?To add an orderTo delete orders ROR Lab.
    • 15. For what?To add an orderTo delete orders ROR Lab.
    • 16. Associations Parent Class Child Class has_one1 :1 belongs_to has_one, :through1 :n has_many belongs_to has_many A has_many B, :through belongs_ton :m has_many B has_many A, :through has_and_belongs_to_many ROR Lab.
    • 17. Association Optionsbelongs_to options has_one options has_many options HABTM options• :autosave • :as • :as • :association_foreign_key• :class_name • :autosave • :autosave • :autosave• :conditions • :class_name • :class_name • :class_name• :counter_cache • :conditions • :conditions • :conditions• :dependent • :dependent • :counter_sql • :counter_sql• :foreign_key • :foreign_key • :dependent • :delete_sql• :include • :include • :extend • :extend• :polymorphic • :order • :finder_sql • :finder_sql• :readonly • :primary_key • :foreign_key • :foreign_key• :select • :readonly • :group • :group• :touch • :select • :include • :include• :validate • :source • :limit • :insert_sql • :source_type • :offset • :join_table • :through • :order • :limit • :validate • :primary_key • :offset • :readonly • :order • :select • :readonly • :source • :select • :source_type • :uniq • :through • :validate • :uniq • :validate ROR Lab.
    • 18. belongs_to vs has_one• “belongs_to” model has a foreign key• dependent upon the actual meaning of data ROR Lab.
    • 19. has_many :through vshas_and_belongs_to_many๏ has_many - validations, callbacks, or extra attributes๏ has_and_belongs_to_many - no need for additional functionalities - should create a “join” table in the DB. ROR Lab.
    • 20. Join Table HABTM• Default join table btw Customer & Order models : custormers_orders• Otherwise, :join_table => “join_table_name” ROR Lab.
    • 21. Join Table HABTM ROR Lab.
    • 22. Join Table HABTM no need for join model ROR Lab.
    • 23. Polymorphic Employee id Product id ROR Lab.
    • 24. Polymorphic Employee Picture id Product id ROR Lab.
    • 25. Polymorphic Employee Picture id employee_id Product id ROR Lab.
    • 26. Polymorphic Employee Picture id employee_id Product Picture id ROR Lab.
    • 27. Polymorphic Employee Picture id employee_id Product Picture id product_id ROR Lab.
    • 28. Polymorphic Employee Picture id employee_id x Product Picture id product_id ROR Lab.
    • 29. Polymorphic Imageable Picture id imageable_id Imageable Picture id imageable_id ROR Lab.
    • 30. Polymorphic Imageable Picture Employee id id imageable_id Imageable Picture Product id id imageable_id ROR Lab.
    • 31. Polymorphic Model Class ROR Lab.
    • 32. Polymorphic Migration ROR Lab.
    • 33. Self Joins• ex. : following or follower ROR Lab.
    • 34. Screencastfor Self JoinPlease click the above link ROR Lab.
    • 35. :include• To eager-load the second-order association ROR Lab.
    • 36. :include• To eager-load the second-order association @line_item.order.customer ROR Lab.
    • 37. :include• To eager-load the second-order association @line_item.order.customer ROR Lab.
    • 38. :counter_cacheNT(*) from ... ROR Lab.
    • 39. :counter_cache @customer.orders.sizeNT(*) from ... ROR Lab.
    • 40. :counter_cache@customer.orders.size SELECT COUNT(*) from ... ROR Lab.
    • 41. :counter_cache@customer.orders.size SELECT COUNT(*) from ... ROR Lab.
    • 42. :counter_cache• But, you should add “orders_count” column to Customer model• You can override the default column name.• ReadOnly !!! ROR Lab.
    • 43. :counter_cache• But, you should add “orders_count” column to Customer model• You can override the default column name.• ReadOnly !!! ROR Lab.
    • 44. Screencast for Belongs_to:counter_cache Please click the above link ROR Lab.
    • 45. :touch• Automatically set :updated_at or :update_on to current timestamp whenever child objects are saved or updated ROR Lab.
    • 46. :touch ROR Lab.
    • 47. :touch ROR Lab.
    • 48. :touchOr using a custom attribute ROR Lab.
    • 49. :touchOr using a custom attribute ROR Lab.
    • 50. 감사합니다. ROR Lab.