Guest User

Untitled

a guest
Sep 12th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. An association is a link between two separate tables; the connection between two tables.
  2.  
  3. Breaking a table into multiple tables and then reducing down to non-duplicating data is called NORMALIZATION.
  4.  
  5. You must always document the association between two connected instances: IDs are the default way of documenting the association
  6. to a foreign table. It’s referred to as the “foreign key.” In Rails, it is assumed it’s the ID. A foreign key must always be an integer.
  7.  
  8. ‘One to many” relationship —> many cows being associated with the same single instance on a foreign table.
  9.  
  10. The table that has the “one” has the foreign key. For example, a User Table and a Tweet Table. The Tweet table would include the
  11. foreign key that would be associated with an instance on the User table.
  12.  
  13. MANY COWS to one farmer. Foreign key on the cow table, that refers back to whose cow it is. Cows belong to farmer. Cows get the key.
  14. MANY TWEETS to one user. Foreign key on the tweets table, that refers back to whose tweet it is. Tweets belong to user. Tweets get the key.
  15. MANY IMAGES to one product. Foreign key on the image table, that refers back to whose image it is. Images belong to product.
  16.  
  17. Think of the foreign key as if we’re branding something. The things that are many need to belong to something.
  18. That is shown with a foreign key. The foreign key “documents the association.” You need to document the association on the
  19. thing that belongs to another thing. Brand the cow, not the farmer. The foreign key says “this thing…belongs to that.”
  20. Foreign keys = branding = belongs to.
  21.  
  22. Product.all.each { |product| product.update(supplier_id: rand(1..3))
  23.  
  24. array.sample = randomly chosen element from the array
  25.  
  26. MOTD
  27.  
  28. JavaScript
  29.  
  30. array.pop
  31.  
  32. Removes the last element of an array AND returns it.
  33.  
  34. let plants = ['broccoli', 'cauliflower', 'cabbage', 'kale', 'tomato'];
  35.  
  36. console.log(plants.pop());
  37. // "tomato"
  38.  
  39. console.log(plants);
  40. // ["broccoli", "cauliflower", "cabbage", "kale"]
  41.  
  42. plants.pop();
  43. // nothing logged in the console
  44.  
  45. console.log(plants);
  46. // ["broccoli", "cauliflower", "cabbage"]
Add Comment
Please, Sign In to add comment