-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
has_many
association gets scaffolded improperly with join-model
scaffolder
#658
Comments
This one might be a bit tough to solve. bullet_train-core/bullet_train-super_scaffolding/lib/scaffolding/transformer.rb Lines 581 to 582 in cdccbdd
I can fix the problem specifically for the model set up in this issue by changing this line to the following (by adding has_many_line = ["has_many :scaffolding_completely_concrete_tangible_things"] However, this breaks our super scaffolding system test. It looks like this is occurring due to a namespace overlap issue. For example, we have this in the Super Scaffolding system test setup The # ✅ This doesn't give us the extra namespace.
"has_many :completely_concrete_tangible_things"
has_many :deliverables
# 🚫 This gives us the whole namespace when we only need `deliverables`
"has_many :scaffolding_completely_concrete_tangible_things"
has_many :projects_deliverables So I think we'll have to do something similar to what's here: Lines 45 to 57 in cdccbdd
|
Now that I've sifted through this a bit, I'm not sure this is a bug. The way we are scaffolding the # Because we're already in the Client namespace `client.rb`,
# " we pop off "clients_" part at the beginning.
has_many :news_articles, class_name: "Clients::NewsArticle", dependent: :destroy
# Also, has_many :news_articles is correct because the model
# we're referring to is News::Article.
# through: :news_articles is also correct because again,
# we're popping off "clients_" since we're already in the Client namespace.
has_many :news_articles, through: :news_articles So, by naming the join model differently, I was able to make everything work properly.
Because of this name overlapping, should we write something in the documentation to avoid this kind of model setup? |
Part of me thinks it's best to simply raise an error telling the developers to reconsider the name of the model they're trying to scaffold if we get something like this: has_many :model_name, :model_name I'm not sure if it's safe to assume that this is only a namespace-specific issue, so I think for now that's the best route we can take. |
This scaffolds the following to
client.rb
.It should be this.
We can add
News::Article
records properly, but trying to accessClients::NewsArticle
via the association yields astack level too deep
error.The text was updated successfully, but these errors were encountered: