bullet_train-core
bullet_train-core copied to clipboard
`has_many` association gets scaffolded improperly with `join-model` scaffolder
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::NewsArticle 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::NewsArticle}
This scaffolds the following to client.rb
.
has_many :news_articles, class_name: "Clients::NewsArticle", dependent: :destroy
has_many :news_articles, through: :news_articles
It should be this.
has_many :clients_news_articles, class_name: "Clients::NewsArticle", dependent: :destroy
has_many :news_articles, through: :clients_news_articles
We can add News::Article
records properly, but trying to access Clients::NewsArticle
via the association yields a stack level too deep
error.
> rails c
Loading development environment (Rails 7.0.8)
irb(main):001> Client.first.news_articles
Client Load (0.5ms) SELECT "clients".* FROM "clients" ORDER BY "clients"."id" ASC LIMIT $1 [["LIMIT", 1]]
/home/gazayas/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/activerecord-7.0.8/lib/active_record/reflection.rb:838:in `through_reflection': stack level too deep (SystemStackError)