DEV Community

SinhueHerrera90
SinhueHerrera90

Posted on

In the middle of the night, I go g acm-ing in my sleep

Okay that's a song that I've been listening to that my mom used to play when we were younger, is called The River of Dreams by Billy Joel

Anyway, I'm here, writing this in the middle of the night while I wrap my head around some of the things that I have learned while working on this photogram project

First off, and something I forgot to mention on my previous post, the g acm "Name your changes" command has been quite helpful, I think it saves time and energy that can be used to have the brain checking for the many typos I usually get on my code

Secondly, when working with data associations, for every belongs_to there has to be a has_many (at least in most of the cases I guess), which of course makes sense, the way I understand this is, let's say there's a script I wrote, that script belongs_to me, however, since I wouldn't have just one, then I would say Sinhue has_many scripts

I also learned that if when adding a column to a data table, we don't necessarily have to write the correct name when writing the command AddNameofColumnnntoTable column_name:data_type; note how I wrote Name of Column vs column_name, this is because once we write the name and the data type, ruby will understand what name to actually put on the column (at least that's how I understood)

Another VERY helpful thing I learned, is that we can change the default value of a column, for example in our exercise, we have a column in a table called USERS, this column refers to the status of an user (private, and it's a boolean), so since I want the default value for this column to be true, I will go ahead and write on my terminal:

rails g migration AddDefaultToPrivate

Then, on our migrations, I will go to this migration file and add the value there in this format:

change_column_default(
table_name,
column_name,
default
)

And of course, once we wrote the changes, we can execute the migration with rails db:migrate

I wonder if I can use that to set up the default value of a column which data type is an integer to 0, since I forgot to add it when creating my data model, I guess I'll have to try it

I also learned about counter_cache, which is used to keep track of the number of associated records in a relationship using a counter column, this is helpful for us, specially as we enter more and more data into our data bases

I am not even halfway through the project and I feel like there's so much information to continue learning, I will update soon as I continue working on it

For now I have to go to sleep DAHLINGS, please feel free to add comments or corrections

xoxoxo

by yours truly

Sinhue

Top comments (0)