Question about model relationships in Ecto and Phoenix

I’m not very experienced with database/model relationships, so some help would be nice.

I’m writing a Phoenix app that is basically a blog. Unlike most blogs though, it’s organized by “country”. What I mean is, the user would go to the app, click a country name, and see posts related to that country. Sort of like “categories” or “topic” in a regular blog.

I have an Author -> Posts relationship working well and a Country model. I’m having trouble thinking about how Post and Country should be related. Any help?

The user would go to country/1, not post/1. The reason I have a Country model is because each Country has some data (name, description, image).

I’d also like if it a Post can “belong” to many countries; I may need that in the future.


Perhaps a Country table, a Post table, and a many-to-many mapping table between them?

Had the time to test that out—worked great. Thanks!

Does a Blog only allow posts for a specific country, or can a Blog have posts which can be viewed by multiple countries?

If it’s the former, you’ll want to move the belongs_to relationship on to Blog instead of Post