Phoenix: No longer generate belongs_to relationships when using references in the new generators

Created on 4 Mar 2017  路  6Comments  路  Source: phoenixframework/phoenix

Because there is a higher chance we will get the wrong module name now and because we may end-up accidentally pushing developers to have associations across contexts.

@chrismccord, what do you think?

Most helpful comment

Was confused a lot by missing belongs_to at first.

All 6 comments

I think this is the way to go, but I would continue to generate the belongs_to provided the context already exists and the assoc'd schema lives inside it. Yay/nay?

@chrismccord it is slightly tricky to detect but we can try. The problem is that users in the past were used to write:

post_id:references:posts

But now they need to write:

post_id:references:blog_posts

So we need to figure out if the underscored context is a prefix of "blog_posts". It is definitely possible but it looks iffy.

ah I see. :+1: to not generating belongs_to for now

Fixed in master.

Specifying blog_posts makes perfect sense to me. Former Django dev here and this all makes me feel right at home.

Was confused a lot by missing belongs_to at first.

Was this page helpful?
0 / 5 - 0 ratings