Currently having a query for filter with parameters premium_amount_lower_range, premium_amount_upper_range, application_date_lower_range, application_date_upper_range, insurance_type_id
@filtered_quotes = current_user.insurance_subscribers.includes(:insurance_types).includes(:insurance_subscribers_types, :insurance_subscribers_types_carriers).
premium_amount(params[:dashboard][:premium_amount_lower_range], params[:dashboard][:premium_amount_upper_range]).
duration(params[:dashboard][:application_date_lower_range], params[:dashboard][:application_date_upper_range]).
insurance_type(params[:dashboard][:insurance_type_id])
But Now need to filter according to their status also. Having problem with it.
I have status column in insurance_subscribers
and insurance_subscribers_types_carriers
tables, both columns are enum.
I tried to add where clause like
@filtered_quotes = current_user.insurance_subscribers.includes(:insurance_types).includes(:insurance_subscribers_types, :insurance_subscribers_types_carriers).
where("insurance_subscribers_types_carriers.status = 1")
# ...
This is giving me error PG::UndefinedTable: ERROR: missing FROM-clause entry for table "insurance_subscribers_types_carriers"
but when i try to do like
@filtered_quotes = current_user.insurance_subscribers.includes(:insurance_types).includes(:insurance_subscribers_types, :insurance_subscribers_types_carriers).
where(status: 1)
# ....
This will put the where clause on insurance_subscribers.
Trying to add a simple where clause WHERE insurance_subscribers_types_carriers.status = 1
in above query but Having so much trouble with this query.
Associations
insurance_subscriber.rb
has_many :insurance_subscribers_types, dependent: :destroy
has_many :insurance_types, through: :insurance_subscribers_types
has_many :insurance_subscribers_types_carriers, through: :insurance_subscribers_types
insurance_types.rb
has_many :insurance_subscribers, through: :insurance_subscribers_types
has_many :insurance_subscribers_types
has_many :insurance_subscribers_types_carriers
insurance_subscriber_type.rb
belongs_to :insurance_subscriber
belongs_to :insurance_type
has_many :carriers, through: :insurance_subscribers_types_carriers
has_many :insurance_subscribers_types_carriers, dependent: :destroy
insurance_subscribers_types_carrier.rb
belongs_to :carrier
belongs_to :insurance_subscribers_type
insurance _types
,insurance_subscribers
andinsurance_subscribers_type_carriers
? Please add all the associations