• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
ActiveRecord Associations (1), Season 1
 

ActiveRecord Associations (1), Season 1

on

  • 4,341 views

제7차 ROR Lab. 강의록

제7차 ROR Lab. 강의록

Statistics

Views

Total Views
4,341
Views on SlideShare
2,139
Embed Views
2,202

Actions

Likes
2
Downloads
15
Comments
1

16 Embeds 2,202

http://rorlab.org 1153
http://lab.wordstory.net 796
http://www.rorlab.org 53
http://kinnet.host 52
http://l 47
http://localhost 38
http://211.60.184.138 24
http://kt.rorlab.org 10
http://sns.rorlab.org 7
http://0.0.0.0 5
http://ns.rorlab.org 4
http://cisoh.ncc.re.kr 4
http://livecoding.rorlab.org 3
http://ror.la 3
http://webcache.googleusercontent.com 2
http://www.hanrss.com 1
More...

Accessibility

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel

11 of 1 previous next

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • http://www.slideshare.net/hyoseongchoi/activerecord-associations-2
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \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

ActiveRecord Associations (1), Season 1 ActiveRecord Associations (1), Season 1 Presentation Transcript

  • The 7th Round of ROR Lab.Active RecordAssociations - 1 February 18th, 2012 Hyoseong Choi ROR Lab.
  • For what? ROR Lab.
  • For what?To add an order ROR Lab.
  • For what?To add an order ROR Lab.
  • For what?To add an orderTo delete orders ROR Lab.
  • For what?To add an orderTo delete orders ROR Lab.
  • For what?• Automation of connecting btw models• Automatic assignment of foreign key ROR Lab.
  • For what? Primary & Foreign Keyscustomer order id id ROR Lab.
  • For what? Primary & Foreign Keyscustomer order id id customer_idparent obj. child obj. ROR Lab.
  • For what? Primary & Foreign Keyscustomer order id id Active Record customer_id Assocationparent obj. child obj. ROR Lab.
  • For what? ROR Lab.
  • For what?To add an order ROR Lab.
  • For what?To add an order ROR Lab.
  • For what?To add an orderTo delete orders ROR Lab.
  • For what?To add an orderTo delete orders ROR Lab.
  • 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.
  • 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.
  • belongs_to vs has_one• “belongs_to” model has a foreign key• dependent upon the actual meaning of data ROR Lab.
  • 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.
  • Join Table HABTM• Default join table btw Customer & Order models : custormers_orders• Otherwise, :join_table => “join_table_name” ROR Lab.
  • Join Table HABTM ROR Lab.
  • Join Table HABTM no need for join model ROR Lab.
  • Polymorphic Employee id Product id ROR Lab.
  • Polymorphic Employee Picture id Product id ROR Lab.
  • Polymorphic Employee Picture id employee_id Product id ROR Lab.
  • Polymorphic Employee Picture id employee_id Product Picture id ROR Lab.
  • Polymorphic Employee Picture id employee_id Product Picture id product_id ROR Lab.
  • Polymorphic Employee Picture id employee_id x Product Picture id product_id ROR Lab.
  • Polymorphic Imageable Picture id imageable_id Imageable Picture id imageable_id ROR Lab.
  • Polymorphic Imageable Picture Employee id id imageable_id Imageable Picture Product id id imageable_id ROR Lab.
  • Polymorphic Model Class ROR Lab.
  • Polymorphic Migration ROR Lab.
  • Self Joins• ex. : following or follower ROR Lab.
  • Screencastfor Self JoinPlease click the above link ROR Lab.
  • :include• To eager-load the second-order association ROR Lab.
  • :include• To eager-load the second-order association @line_item.order.customer ROR Lab.
  • :include• To eager-load the second-order association @line_item.order.customer ROR Lab.
  • :counter_cacheNT(*) from ... ROR Lab.
  • :counter_cache @customer.orders.sizeNT(*) from ... ROR Lab.
  • :counter_cache@customer.orders.size SELECT COUNT(*) from ... ROR Lab.
  • :counter_cache@customer.orders.size SELECT COUNT(*) from ... ROR Lab.
  • :counter_cache• But, you should add “orders_count” column to Customer model• You can override the default column name.• ReadOnly !!! ROR Lab.
  • :counter_cache• But, you should add “orders_count” column to Customer model• You can override the default column name.• ReadOnly !!! ROR Lab.
  • Screencast for Belongs_to:counter_cache Please click the above link ROR Lab.
  • :touch• Automatically set :updated_at or :update_on to current timestamp whenever child objects are saved or updated ROR Lab.
  • :touch ROR Lab.
  • :touch ROR Lab.
  • :touchOr using a custom attribute ROR Lab.
  • :touchOr using a custom attribute ROR Lab.
  • 감사합니다. ROR Lab.