Open gazayas opened 1 year ago
This one might be a bit tough to solve.
I can fix the problem specifically for the model set up in this issue by changing this line to the following (by adding scaffolding_
).
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 has_many
association gets scaffolded in the following way:
# ✅ 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:
Now that I've sifted through this a bit, I'm not sure this is a bug. The way we are scaffolding the has_many
lines is technically correct. Here's another look.
# 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.
bin/super-scaffold crud News::Article Team title:text_field
bin/super-scaffold crud Client Team title:text_field
bin/super-scaffold join-model Clients::TestArticle news_article_id{class_name=News::Article} client_id{class_name=Client}
bin/super-scaffold crud-field News::Article client_ids:super_select{class_name=Clients::TestArticle}
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.