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

feature: summarizable associations #3428

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

thiagoyoussef
Copy link
Contributor

Description

Fixes #2993

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works

Screenshots & recording

CleanShot 2024-11-15 at 13 14 34

Copy link

codeclimate bot commented Nov 15, 2024

Code Climate has analyzed commit b3f357b and detected 0 issues on this pull request.

View more on Code Climate.

@thiagoyoussef thiagoyoussef force-pushed the feature/summarizable-associations branch from 0036e9c to 26835c0 Compare November 15, 2024 17:11
Copy link
Contributor

@Paul-Bob Paul-Bob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good overall. The scope on association is not applying as expected

image

Let's ensure that we apply the field scope option instead of fetching all associated records using parent.send(association_name).

Copy link
Contributor

@Paul-Bob Paul-Bob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've provided some code snippets with suggestions (not tested) on how we might apply the scope from the association field

Comment on lines +17 to +19
query = resource.authorization&.apply_policy related_records

Avo::ExecutionContext.new(target: resource.search_query, query: query).handle
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
query = resource.authorization&.apply_policy related_records
Avo::ExecutionContext.new(target: resource.search_query, query: query).handle
related_records

Comment on lines +25 to +32
def related_records
relation_class = BaseResource.get_model_by_name(params[:via_relation_class])
parent = relation_class.find(params[:via_record_id])

association_name = BaseResource.valid_association_name(parent, resource.model_key)

parent.send(association_name)
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def related_records
relation_class = BaseResource.get_model_by_name(params[:via_relation_class])
parent = relation_class.find(params[:via_record_id])
association_name = BaseResource.valid_association_name(parent, resource.model_key)
parent.send(association_name)
end
def related_records
relation_class = BaseResource.get_model_by_name(params[:via_relation_class])
parent = relation_class.find(params[:via_record_id])
association_name = BaseResource.valid_association_name(parent, resource.model_key)
parent_resource = ...
association_field = ...
query = resource.authorization.apply_policy parent.send(association_name)
Avo::ExecutionContext.new(
target: association_field.scope,
query: query,
parent: parent,
resource: resource,
parent_resource: parent_resource
).handle
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make summarizable work under association pages
2 participants