-
Notifications
You must be signed in to change notification settings - Fork 10
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
How to deal with chained associations? #66
Comments
rails_select_on_includes gem solves the issue of eager_load wiping virtual attributes. |
This is not perfect, but allows stuff like association %i[vendor parent], :name, filter: :exact, sortable: true |
Can you give me an example on which |
I'm about to clear up the patch before PR. I think it is better to use (more) dashes instead of colons for nested associations. Meanwhile here is what causes issues with at least Rails 4.2.10 with Ruby 2.4.4. This is a far fetched example as there is only 1 level of associations that is handled well as is with tabulatr2, but if I were to use some fancy Arel expression and a bunch of tables, the result would be the same. We ought to use hash with eager loading and, perhaps, there will be no need in fancy queries in advance and we could leave diff --git a/spec/dummy/app/controllers/products_controller.rb b/spec/dummy/app/controllers/products_controller.rb
index aff292d..e783c51 100644
--- a/spec/dummy/app/controllers/products_controller.rb
+++ b/spec/dummy/app/controllers/products_controller.rb
@@ -1,7 +1,8 @@
class ProductsController < ApplicationController
def simple_index
- tabulatr_for Product
+ p = Product.joins(:vendor).select('*')
+ tabulatr_for p
end
def one_item_per_page_with_pagination
P.S. Just to clarify the need. One may use regular column definition with aforementioned approach to get attributes coming from deeply joined tables instead of using blocks and re-querying the chain. |
This closes metaminded#66 # Conflicts: # lib/tabulatr/data/dsl.rb
This closes metaminded#66
This closes metaminded#66
This closes metaminded#66
This closes metaminded#66
This closes metaminded#66
This closes metaminded#66
This closes metaminded#66
This closes metaminded#66
I want to (left) join like 5 tables into a flattened representation with tabulatr2. Defining a block for each column would be inefficient. I have been getting by with views on DB side, but I wonder if there is a better approach. If I somewhat manually form a query and select extra columns I want, those are gone after eager_load call from join_required_tables. What would be the canonical approach? Allow arrays of associations?
The text was updated successfully, but these errors were encountered: