Rails: I've summarized the model and database for a moment.

At first

** Day 15 of Calendar Planning 2020 ** It's been about 3 months since I started studying programming, so I will leave a note of what I learned in the article as an output. I would be happy if I could help anyone entering the world of programming. Please let me know if there are any words that are wrong, wrong, or misunderstood ^^ I'm sorry if it's hard to read the words for a long time. I will do my best to get used to it little by little.

Let's summarize the model and database (DB)

What is a model?

The model is briefly described here

Where to handle application data. It plays a role in processing such as registering, acquiring, updating, and deleting data in the database. For example I think it's an image of managing a huge warehouse called a database. It feels like it retrieves and stores the information you need when you need it.

It is basically an exchange with the DB.

What is a database (DB)?

DB is the data storage destination. Thanks to DB, data can be saved and searched efficiently.

Is it the place where the memory card or save data in the game is saved? model is the game console It doesn't come out this time, but Controller is a controller I wonder if the code displayed on the TV screen and the TV will be View! That's the image.

In rails, the data saved in the DB is collected in ** "table" ** and the tables are saved in relation to each other.

The table keeps the data organized, making it easier to retrieve the data.

Isn't it difficult to find the latest one if the past save data is in a mess in the game? In order to eliminate such a thing, it is called a table, so related things are saved in an easy-to-understand manner.

A little more about the table

Imagine a blog site.

--Title

Suppose you have this information.

If you try to make these into a table

ID title Text Contributor Posted date
1 Nice to meet you I will start blogging from today yuta 12/1
2 Such a sky is amazing Blue sky this morning yuta 12/5
3 Where are you today? Look at the photo and guess yuta 12/9
4 from morning,,, I work silently yuta 12/12

I feel like this. It's like Excel! But that's exactly the image! !! By doing this, it's easy to see where and when you posted the title! This is to keep things tidy and easy to understand.

The table also has a name The whole thing is called ** table **. Column: It is called ** column **. Row: Say ** record **.

In rails, ID is automatically generated when a table is created and data is created. What is the record with ID1?

ID title Text Contributor Posted date
1 Nice to meet you I will start blogging from today yuta 12/1

What are the column names in this table?

ID title Text Contributor Posted date

It will be this.

What's in the title column?

title
Nice to meet you
Such a sky is amazing
Where are you today?
from morning,,,

These are extracted.

Data is exchanged with the DB in the database language (SQL).

Finally

To be honest, I remembered that it was difficult at first to understand the column ^^; You can see it here, but what if you actually make it? I was often confused. ^^;

Recommended Posts

Rails: I've summarized the model and database for a moment.
I summarized the naming conventions for each Rails
A note about the Rails and Vue process
Explanation of Ruby on rails for beginners ③ ~ Creating a database ~
With the software I've been making for a long time ...
I made a reply function for the Rails Tutorial extension (Part 1)
(Ruby on Rails6) Creating a database and displaying it in a view
Explanation of Ruby on rails for beginners ⑤ ~ Edit and delete database ~
I made a reply function for the Rails Tutorial extension (Part 5):
Install Rails in the development environment and create a new application
Create a development environment for Ruby 3.0.0 and Rails 6.1.0 on Ubuntu 20.04.1 LTS
Relationship between database and model (basic)
Rails model and table naming conventions
Gorigori beginners summarized how to operate the database using rails console Ntiunus
[Docker] How to create a virtual environment for Rails and Nuxt.js apps
[Rails] How to create a table, add a column, and change the column type
[Rails] Articles for beginners to organize and understand the flow of form_with
I made a reply function for Rails Tutorial extension (Part 2): Change model
A review note for the class java.util.Scanner
[Rails] Unit test code for User model
Change the default timezone for the rails app
Now, I've summarized the basics of RecyclerView
Prepare the security check environment for Rails 6
A review note for the class java.util.Optional
A review note for the class java.util.Objects
A simple and convenient method for HashMap
[Rails] Reset the database in the production environment
A review note for the package java.time.temporal
[Rails] We have summarized the storage locations and usage of developer and user images.
Do you use the for statement after all? Do you use a while statement? Proper use of for statement and while statement
Find out about Rails hidden_field (create a confirmation screen and check the behavior)