Is an ActiveRecord object in the request?

Is this a more concise way of writing this post:

current_user.products.where(:product_id => product.id).present? 

Do the rails have something like?

 current_user.products.has? product 

I know that I can:

 current_user.products.include? product 

... but which downloads all products. I am trying to get an intelligent request from it.

+4
source share
1 answer

Can you use the exists? method exists? . How:

 current_user.products.exists?(product.id) 

You can take a look at the Guide to Active Record Request Interface and API .

+4
source

All Articles