Reputation: 4187
Now i tried to add a new ActiveRecord relation object that i get from the database to the new empty ActiveRecord relation object that i made it by .none method
But it seems like i do not know the way to do it. This is my code
def customer_prb_insurance_table
@customer_prb_insurance_array = CustomerPrbInsurance.none
@prb_type = params[:type]
@prb_insurance_objects = PrbInsurance.where(prb_type: params[:type])
@prb_insurance_objects.each do |prb_insurance_object|
prb_customers = prb_insurance_object.customer_prb_insurances
prb_customers.each do |prb_customer|
puts "are y rady"
puts @customer_prb_insurance_array
puts "i am cote"
puts prb_customer.inspect
puts "yolololololo"
@customer_prb_insurance_array << prb_customer
puts @customer_prb_insurance_array
byebug
end
end
@customer_prb_insurance_array = @customer_prb_insurance_array.paginate(:page => params[:page])
end
Then this is what i got from the server log.
are y rady
i am cote
#<CustomerPrbInsurance id: 396, first_name: "Adonis", last_name: "Considine", tel_number: "1-171-422-3411", email: "[email protected]", time_call_back: "evening", prb_insurance_id: 10, created_at: "2016-06-03 19:14:03", updated_at: "2016-06-03 19:14:03">
yolololololo
Return value is: nil
So how to fix this?
Thanks!
Upvotes: 0
Views: 534
Reputation: 16514
Seems you have top complex relation serving code, to select all the customers try the follwing sql relation, implying that you have in CustomerPrbInsurance
property :prb_insurance
, which belongs to PrbInsurance
:
class CustomerPrbInsurance
belongs_to :prb_insurance
scope :by_prb_type, -> {|type|
joins(:prb_insurance).where(prb_insurance: { prb_type: type })
}
end
then:
CustomerPrbInsurance.by_prb_type(params[:type])
Upvotes: 1