Closed mespina closed 3 years ago
Hi there! Thanks for this PR! Can you please add some tests?
I think this case is now handled in Rails 6.1 :
Started POST "/transactions/datatable.json" for 127.0.0.1 at 2021-01-04 04:54:27 +0100
Processing by TransactionsController#datatable as JSON
Parameters: {"draw"=>"7", "columns"=>{"0"=>{"data"=>"id", "name"=>"Id", "searchable"=>"true", "orderable"=>"true", "search"=>{"value"=>"", "regex"=>"false"}}, "1"=>{"data"=>"seller", "name"=>"Seller", "searchable"=>"true", "orderable"=>"true", "search"=>{"value"=>"", "regex"=>"false"}}, "2"=>{"data"=>"buyer", "name"=>"Buyer", "searchable"=>"true", "orderable"=>"true", "search"=>{"value"=>"", "regex"=>"false"}}, "3"=>{"data"=>"amount", "name"=>"Amount", "searchable"=>"true", "orderable"=>"true", "search"=>{"value"=>"", "regex"=>"false"}}}, "order"=>{"0"=>{"column"=>"1", "dir"=>"asc"}}, "start"=>"0", "length"=>"10", "search"=>{"value"=>"", "regex"=>"false"}, "dtf_debug_log"=>"false", "dtf_debug_dump"=>"false"}
(0.9ms) SELECT COUNT(*) FROM "transactions"
↳ app/controllers/transactions_controller.rb:15:in `block (2 levels) in datatable'
CACHE (0.0ms) SELECT COUNT(*) FROM "transactions"
↳ app/controllers/transactions_controller.rb:15:in `block (2 levels) in datatable'
SQL (1.8ms) SELECT "transactions"."id" AS t0_r0, "transactions"."buyer_id" AS t0_r1, "transactions"."seller_id" AS t0_r2, "transactions"."amount" AS t0_r3, "transactions"."created_at" AS t0_r4, "transactions"."updated_at" AS t0_r5, "users"."id" AS t1_r0, "users"."name" AS t1_r1, "users"."title" AS t1_r2, "users"."content" AS t1_r3, "users"."rooms" AS t1_r4, "users"."enabled" AS t1_r5, "users"."created_at" AS t1_r6, "users"."updated_at" AS t1_r7, "buyers_transactions"."id" AS t2_r0, "buyers_transactions"."name" AS t2_r1, "buyers_transactions"."title" AS t2_r2, "buyers_transactions"."content" AS t2_r3, "buyers_transactions"."rooms" AS t2_r4, "buyers_transactions"."enabled" AS t2_r5, "buyers_transactions"."created_at" AS t2_r6, "buyers_transactions"."updated_at" AS t2_r7 FROM "transactions" LEFT OUTER JOIN "users" ON "users"."id" = "transactions"."seller_id" LEFT OUTER JOIN "users" "buyers_transactions" ON "buyers_transactions"."id" = "transactions"."buyer_id" ORDER BY users.name ASC LIMIT $1 OFFSET $2 [["LIMIT", 10], ["OFFSET", 0]]
↳ app/datatables/transactions_datatable.rb:16:in `map'
Completed 200 OK in 17ms (Views: 12.9ms | ActiveRecord: 2.7ms | Allocations: 3763)
There is a test case here : https://github.com/jbox-web/ajax-datatables-rails-sample-project
Looks nice, hope can merge and release a new version.