Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- An association is a link between two separate tables; the connection between two tables.
- Breaking a table into multiple tables and then reducing down to non-duplicating data is called NORMALIZATION.
- You must always document the association between two connected instances: IDs are the default way of documenting the association
- 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.
- ‘One to many” relationship —> many cows being associated with the same single instance on a foreign table.
- 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
- foreign key that would be associated with an instance on the User table.
- 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.
- 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.
- MANY IMAGES to one product. Foreign key on the image table, that refers back to whose image it is. Images belong to product.
- Think of the foreign key as if we’re branding something. The things that are many need to belong to something.
- That is shown with a foreign key. The foreign key “documents the association.” You need to document the association on the
- thing that belongs to another thing. Brand the cow, not the farmer. The foreign key says “this thing…belongs to that.”
- Foreign keys = branding = belongs to.
- Product.all.each { |product| product.update(supplier_id: rand(1..3))
- array.sample = randomly chosen element from the array
- MOTD
- JavaScript
- array.pop
- Removes the last element of an array AND returns it.
- let plants = ['broccoli', 'cauliflower', 'cabbage', 'kale', 'tomato'];
- console.log(plants.pop());
- // "tomato"
- console.log(plants);
- // ["broccoli", "cauliflower", "cabbage", "kale"]
- plants.pop();
- // nothing logged in the console
- console.log(plants);
- // ["broccoli", "cauliflower", "cabbage"]
Add Comment
Please, Sign In to add comment