jeudi 30 juillet 2015

has_many :through how it works?

First of all let me say that I come from oldschool php framework and outdated practices that I'm struggling to undo them. When the PHP I found situations N-N I simply created a new table and was 1-N relationship with this new table. Example:

tbl_users

tbl_posts

Relationship:

tbl_users N-N tbl_posts

So I just created in the new table and made 1-N relationship (common has_many). Example:

tbl_users 1-N tbl_like_posts

tbl_posts 1-N tbl_like_posts

I do not know if there was something equivalent and I did not use because I was never charged. But the reality is that I've looked on the has_many: through and fail to make it into my head. Why can I not do what I did before? What: through is special? What it will ease me? I even understand how to use, but did not understand why to use.

I'm sorry if the question was kind of silly, but I'm trying to drop PHP addictions and learn the rails correctly.

Aucun commentaire:

Enregistrer un commentaire