-
-
Notifications
You must be signed in to change notification settings - Fork 277
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
Issues with has_many relation for STI model #3406
Comments
Hey @sandraa-nestor. Here's a quick command that will help you generate a new Avo app in no-time. Thank you! |
I'll address point 1 from the issue. No need to include the policies in the reproduction repository, but please do it with the point 2. By default, each resource has a one-to-one mapping with a policy, with that policy being determined based on the model class tied to the resource. For example:
When Avo determines which policy class to use, it simply appends In your scenario, it seems logical to manage both resources with a single policy file. You can accomplish this by specifying the class Avo::Resources::BankAccount < Avo::BaseResource
self.authorization_policy = SystemEntityPolicy
def fields
field :system_entity, as: :belongs_to, only_on: [:new, :show, :index]
end
end |
Ahh, I see that... I had an class Avo::Resources::SystemEntity < Avo::Resources::Entity
self.model_class = ::Entities::System
self.authorization_policy = SystemEntityPolicy
...
end Now policy works fine, thank you @Paul-Bob! |
Hey @adrianthedev! class Users::Student < User
has_many :marks, foreign_key: :student_id
end Here is my reproduction repo Screen.Recording.2024-11-12.at.13.47.31.mov |
Thank you for the reproduction repository @sandraa-nestor I'll have a look |
Setting the class Users::Student < User
has_many :marks, foreign_key: :student_id, inverse_of: :student
end Avo occasionally leans on model reflections, particularly when it comes to association fields. Rails usually handles My recommendation? Just go ahead and declare Marking this as done, but feel free to reopen or keep chatting if needed! |
I'm reopening this issue to explore the possibility of identifying this use case and raising a developer-friendly error to prompt the setting of |
Describe the bug
STI model
class Entities::System < Entity
with relationhas_many :bank_accounts
Bank account model
class BankAccount < ApplicationRecord
withbelongs_to :system_entity, class_name: "Entities::System"
Association policies on STI models are ignored. Cannot hide

Attach bank account
button in tab inSystemEntityPolicy.
When creating Bank account through parent resource

belongs_to
selector of System Entity is not set automatically:avo/resources/bank_accounts/new?via_record_id=2&via_relation=bank_accounts&via_relation_class=Entities::System&via_resource_class=Avo::Resources::SystemEntity
Models and resource files
Expected behavior & Actual behavior
Expected behavior: bank accounts can be managed through
SystemEntityPolicy
Actual behavior:
SystemEntityPolicy
has no impact on Bank accounts tabExpected behavior: bank accounts can be created through parent resource with correctly selected System Entity
Actual behavior: the selector is blank
System configuration
Avo version: 3.13.7
Rails version: 7.2.2
Ruby version: 3.3.4
License type:
Are you using Avo monkey patches, overriding views or view components?
Impact
Urgency
The text was updated successfully, but these errors were encountered: