bullet-train-pro / bullet_train-action_models

Other
5 stars 1 forks source link

Conflicting associations in `targets-one-parent` when parent is `Team` #20

Closed gazayas closed 1 year ago

gazayas commented 2 years ago

Steps to reproduce

rails g model Listing team:references name:string
bin/super-scaffold crud Listing Team name:text_field --sidebar="ti.ti-world"
rails db:migrate
bin/super-scaffold action-model:targets-one-parent CsvImport Listing Team

When trying to access the dashboard, you get a stack level too deep error.

The cause

app/views/account/listings/csv_import_actions/_new_button_many.html.erb:

<% if can? :create, Listings::CsvImportAction.new(team: team) %>
  <%= button_to "Csv Import", [:new, :account, team, :listings_csv_import_action], method: :get, class: 'button-secondary', form: {class: 'button_to'} %>
<% end %>

Listings::CsvImportAction.new(team: team) here is causing the error because there are conflicting associations in the model:

belongs_to :team, class_name: "Team"
# 🚅 add belongs_to associations above.

# 🚅 add has_many associations above.

has_one :team, through: :team
# 🚅 add has_one associations above.

Removing has_one takes care of the error, but we should edit these when scaffolding based on whether the parent is Team or not.

gazayas commented 1 year ago

Closing this one because #26 was merged, the targets-one-parent tests are passing in the starter repository, and I'm not getting the stack level too deep error anymore when accessing the dashboard.