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. Playerbelongs_to :team and Teamhas_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:
🐛 However, Players are not shown when viewing Teams (list, edit, show, etc.):
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
andPlayer
.Player
belongs_to :team
andTeam
has_many :players
. ThePlayer
model has adefault_scope
which excludes "inactive" players:Players
are unscoped and shown in the/player
route in Rails Admin, as expected:🐛 However,
Players
are not shown when viewingTeams
(list, edit, show, etc.):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.3rails_admin
version: 3.1.2rails_admin
npm package version: 3.1.2