Giter VIP home page Giter VIP logo

ruby-relationships-online-seng-ft-061520's Introduction

Associations (Associated Objects) in Ruby

Goals

  • Build two classes that have a has-many/belongs-to relationship
  • Describe different kinds of relationships
  • talk about file structure (a bit of a tangent)

Different types of relationships

"Even objects have relationships?" - Neivy's sister "Yes." "What do we mean? How objects relate or communicate with each other. How they're connected." - Wendy

  • has_one example: typically, "A husband has one wife" (The opposite is also true)
  • has_many one object "has many" of another...
    • a has_many is complemented by either a belongs_to or has_many
  • a has_many/belongs_to relationship, also called "one to many", is what we're going to talk about today

Can we think of a real-world one-to-many relationship?

  • rabbit/carrots
  • library/books
  • teacher/students
  • leader/followers

To make this work, we will establish:

  • A library class
  • A book class

We need to consider both sides of a relationship. As we add a book to a library's collection, for example, we also need to add the library to the book. And vice versa.

In this code we now have a very basic example of a has-many/belongs-to relationship. This is the very tiny tip of a rather large iceberg that we will be exploring much further in mod 2. Going forward, we will focus on the project.

ruby-relationships-online-seng-ft-061520's People

Contributors

howardbdev avatar

Watchers

James Cloos avatar  avatar

Forkers

benjaminghray

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.