DEV Community

Discussion on: Avoid Ransack's N+1 Pitfall!

Collapse
defman profile image
Sergey Kislyakov πŸ‡·πŸ‡Ί πŸ‡ΊπŸ‡Έ

Any reasons not to use relations and joins?

Collapse
husteadrobert profile image
Robert Hustead Author

Sorry for the late reply!

I'm not sure I understand your question. In the example, Service and Provider are related, and I suppose you could do something like,

@q = Service.all.joins(:provider).ransack(params[:q])

perhaps? But I have not tested it. Moreover, this would bypass any resource authorization libraries (like Cancan)