avo-hq / avo

Build Ruby on Rails apps 10x faster
https://avohq.io
Other
1.43k stars 223 forks source link

Scope belongs_to based on parent record #2872

Open rctneil opened 2 weeks ago

rctneil commented 2 weeks ago

Hi,

I have a belongs to which is searchable. I want to limit the results to only those that match the selected Venue of the Visit that I am creating.

My Cycle Resource has this field:

field :cyclable, as: :belongs_to, polymorphic_as: :cyclable, types: [::Attraction], searchable: true, name: "Attraction", attach_scope: -> { query.from_visit_venue_only }

my Attraction Model has this scope:

scope :from_visit_venue_only, -> (parent) { where('venue = ?', parent.visit.venue) }

But I get Undefined method 'find' for nil in the search field.

Any ideas?

18:32:30 web.1    | Started GET "/avo/avo_api/attractions/search?via_record_id=80501&via_relation=visit&via_relation_class=Visit&via_resource_class=Avo::Resources::Visit&q=&global=false&via_association=belongs_to&via_association_id=cyclable&via_reflection_class=Cycle&via_reflection_id=&via_reflection_view=edit&via_parent_resource_id=80501&via_parent_resource_class=Visit" for ::1 at 2024-06-18 18:32:30 +0100
18:32:30 web.1    |   ActiveRecord::SchemaMigration Load (1.3ms)  SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
18:32:30 web.1    |   User Load (0.8ms)  SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2  [["id", 1], ["LIMIT", 1]]
18:32:30 web.1    | Processing by Avo::SearchController#show as */*
18:32:30 web.1    |   Parameters: {"via_record_id"=>"80501", "via_relation"=>"visit", "via_relation_class"=>"Visit", "via_resource_class"=>"Avo::Resources::Visit", "q"=>"", "global"=>"false", "via_association"=>"belongs_to", "via_association_id"=>"cyclable", "via_reflection_class"=>"Cycle", "via_reflection_id"=>"", "via_reflection_view"=>"edit", "via_parent_resource_id"=>"80501", "via_parent_resource_class"=>"Visit", "resource_name"=>"attractions"}
18:32:31 web.1    | [Avo] 2024-06-18 18:32:31 +0100: Performing request to avohq.io API to check license availability.
18:32:32 web.1    |   Attraction Load (8.1ms)  SELECT "attractions".* FROM "attractions" /* loading for inspect */ ORDER BY "attractions"."order_ridden" ASC LIMIT $1  [["LIMIT", 11]]
18:32:32 web.1    | Completed 500 Internal Server Error in 1315ms (Views: 0.2ms | ActiveRecord: 17.0ms | Allocations: 454942)
18:32:32 web.1    |
18:32:32 web.1    |

As far as I can tell, I'm passing the parent through to the scope correctly.

adrianthedev commented 2 weeks ago

I can't see the Undefined method 'find' for nil in the search field. in the stack trace. Can you please find it and send the complete stack trace @rctneil?

adrianthedev commented 2 weeks ago

What would help is a reproduction repo where we can test it. Can you please set one up with the things needed for this reproduction?

rctneil commented 2 weeks ago

rctneil?

This is the issue. When I click the search field, that's all I get in my terminal window. I don't see anything else. I find this a lot with Avo, I don't see much output at the console level.

I'll try to make a repro.

adrianthedev commented 2 weeks ago

rctneil?

This is the issue. When I click the search field, that's all I get in my terminal window. I don't see anything else. I find this a lot with Avo, I don't see much output at the console level.

I'll try to make a repro.

It depends on what's happening. We're not stopping anything from being logged. It's how Rails treats each error.

Yes, please! The reproduction repo really helps. Without logs or reproduction we can't figure it out either.

github-actions[bot] commented 4 days ago

This issue has been marked as stale because there was no activity for the past 15 days.