DEV Community

SinhueHerrera90
SinhueHerrera90

Posted on

A month later, HERE I AM

So, tonight as I am taking back my studying on Ruby on Rails, I was working on a project similar to Instagram, because of the nature of the data model (with users, photos, likes, comments, requests) it is imperative to know how to create the right schema so that my tables work correctly with each other (at least that's how I understand it, please give me feedback if you can explain it better)

So, as I was working on adding my data tables, I realized I made a couple of mistakes, mainly on defining some of the relations that tables have with each other, even though I had already done this before, it was good to remember that sometimes we have to define where our foreign key is coming from, for example, let's say I have a data table for comments, and it references (which is a keyword for associations between two data tables) an :author, I will have to establish where this author is coming from(the foreign key) so a snippet of code on a comments migration that has a connection to a user table through "author" would look like this:

"... t.references :author, null: false, foreign_key: { to_table: :users} ..."

This code of course also takes in account that we want to have an author to each comment (and hence the null:false)

So, all this explanation (or attempt to explain) is just to mention that, after I realized I made a mistake on two of my tables, I had to go back to my previous two migrations, I knew I could do a rails db:rollback to go back to my last migration, so I did that, but then I noticed I had to go back two steps further (or behind should I say) and so I used the rails db:rollback STEP=2 to solve this (it seems like you can go step by step, LITERALLY, when going back to your migrations)

I hadn't really worked with rolling back past my last migration, it seems like this worked 🫣

Anyway, it's a bit late and I am falling asleep, I will check that everything goes smooth with this project and I will continue updating as I work through it

I hope this can help someone or that at least is readable ha ha

See ya!

Sinhue

Top comments (2)

Collapse
 
heratyian profile image
Ian

Keep it up Sinhue 💪

Collapse
 
sinhueherrera90 profile image
SinhueHerrera90

Here I am, five days later wooooo!!! hahaha!!! I'm taking my time with this photogram industrial!