https://avo.cool logo
is there a way to unscope the query for the sho...
# avo-2
e
is there a way to unscope the query for the show and all action and not only the index like:
self.index_query = -> { query.with_deleted }
? Maybe something like:
self.query = -> { query.with_deleted }
m
Thread automatically created by seth likes avo in #740893011994738751
l
Hey @early-oxygen-87878
e
Hey!
l
first of all, best alias name ever!!
e
Sorry I meant to put this in the avo 3 channel
l
😄
DW
there is the
self.find_record_method
that will give you acess to the
query
just edited, check edited ☝️
e
thank you sir
I will try that out
e
There is no way to add a default scope to all queries from a resource like index and show and edit pages?
l
self.find_query_method
didn't work?
This block is called on show / edit views
e
Yeah it works fine just curous if the was a more global way to unscope something. I could not find a way to get the
filterable: true
to be scoped
l
The
self.index_query
is not respected when applying a filter?
e
It does not seem so but i am checking for sure right now again
We can resume tomorrow sorry to bother you so late lol
So the filter is running:
SELECT COUNT(*) FROM "region_courses" WHERE ("region_courses"."deleted_at" IS NOT NULL AND "region_courses"."deleted_at" != NULL)
which is not good sql because the
"region_courses"."deleted_at" != NULL
will always return nothing.
l
No worries, I'll have a better look when I get to the pc
Which action generated that query?
e
Copy code
ruby
web    | Started GET "/avo/resources/region_courses?page=3&filters[deleted_at][is_present][]=" for 127.0.0.1 at 2023-11-07 20:52:17 +0100
web    |    (1.4ms)  SELECT "flipper_features"."key" AS feature_key, "flipper_gates"."key", "flipper_gates"."value" FROM "flipper_features" LEFT OUTER JOIN "flipper_gates" ON "flipper_features"."key" = "flipper_gates"."feature_key"
web    |   ↳ lib/account_middleware.rb:23:in `call'
web    |   User Load (1.9ms)  SELECT "users".* FROM "users" WHERE "users"."deleted_at" IS NULL AND "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2  [["id", 1], ["LIMIT", 1]]
web    |   ↳ lib/account_middleware.rb:23:in `call'
web    | Processing by Avo::RegionCoursesController#index as HTML
web    |   Parameters: {"page"=>"3", "filters"=>{"deleted_at"=>{"is_present"=>[""]}}}
web    | [Avo] 2023-11-07 20:52:17 +0100: Performing request to avohq.io API to check license availability.
web    |   RegionCourse Load (0.9ms)  SELECT "region_courses".* FROM "region_courses" /* loading for inspect */ LIMIT $1  [["LIMIT", 11]]
web    |   ↳ lib/account_middleware.rb:23:in `call'
web    |   RegionCourse Count (0.6ms)  SELECT COUNT(*) FROM "region_courses" WHERE ("region_courses"."deleted_at" IS NOT NULL AND "region_courses"."deleted_at" != NULL)
web    |   ↳ lib/account_middleware.rb:23:in `call'
web    |   RegionCourse Load (0.5ms)  SELECT "region_courses".* FROM "region_courses" WHERE ("region_courses"."deleted_at" IS NOT NULL AND "region_courses"."deleted_at" != NULL) ORDER BY region_courses.created_at desc LIMIT $1 OFFSET $2  [["LIMIT", 24], ["OFFSET", 0]]
the index action with the deleted_at filter
l
Thanks for the details
but there is the issue with the date filters "is present" and "is blank"