Rails has_and_belongs_to_many query for all records -


given following 2 models

class propertyapplication     has_and_belongs_to_many :applicant_profiles end  class applicantprofile     has_and_belongs_to_many :property_applications end 

i have query lists property_applications , gets collection of applicant_profiles each property_application.

the query follows , inefficient.

applications = propertyapplication.includes(:applicant_profile).all.select |property_application|     property_application.applicant_profile_ids.include?(@current_users_applicant_profile_id) 

assume @current_users_applicant_profile_id defined.

how can perform 1 (or few) queries achieve this?

i want achieve this

propertyapplication.includes(:applicant_profile).where('property_application.applicant_profiles in (@current_users_applicant_profile)) 


Comments

Popular posts from this blog

gridview - Yii2 DataPorivider $totalSum for a column -

java - Suppress Jboss version details from HTTP error response -

Sass watch command compiles .scss files before full sftp upload -