Skip to content
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

Associated records not shown when associations have a default scope #3674

Open
rnevius opened this issue Feb 29, 2024 · 0 comments
Open

Associated records not shown when associations have a default scope #3674

rnevius opened this issue Feb 29, 2024 · 0 comments

Comments

@rnevius
Copy link

rnevius commented Feb 29, 2024

Preface

This could be my own misunderstanding about how scoping associated models is expected to configured. I have reviewed the Wiki.

Describe the bug

Let's say we have 2 models, Team and Player. Player belongs_to :team and Team has_many :players. The Player model has a default_scope which excludes "inactive" players:

class Team < ApplicationRecord
  has_many :players, dependent: :destroy

  default_scope { where(active: true) }

  rails_admin do
    configure :players do
      associated_collection_cache_all false
      associated_collection_scope do
        proc { |scope| scope.unscoped }
      end
    end
  end
end

class Player < ApplicationRecord
  belongs_to :team

  default_scope { where(active: true) }

  rails_admin do
    scope { Player.unscoped }
  end
end

Players are unscoped and shown in the /player route in Rails Admin, as expected:

image

🐛 However, Players are not shown when viewing Teams (list, edit, show, etc.):

image

Reproduction steps

Demo repo: https://github.com/rnevius/rails_admin_associated_scope_demo

Relevant code is in the models.

Expected behavior

Unscoped associations should be shown.

Additional context

  • rails version: 7.1.3
  • rails_admin version: 3.1.2
  • rails_admin npm package version: 3.1.2
@rnevius rnevius changed the title Associated records not show when associations have a default scope Associated records not shown when associations have a default scope Feb 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant