Quantcast
Channel: Active questions tagged ruby - Stack Overflow
Viewing all articles
Browse latest Browse all 4645

Preloading nested Rails associations with a condition without updating models

$
0
0

To provide a simple example, let's say I want to load ALL hospitals for an organization and preload ONLY the doctors that have a calendar, but at the same time, I do not want to create any scopes or additional associations in the models, so the models should remain the same. How would I do that?

With some pseudo code, I want something along the lines of:

def find_facilities(organization)  doctors_query = Doctor.joins(:calendar).includes(:calendar)  organization.facilities.preload(doctors: doctors_query)end

It's also important that not only do I want to check that the calendar exists, I also want to preload it.

And another point is that the calendar has a foreign key to the doctors, not the other way around.


Viewing all articles
Browse latest Browse all 4645

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>