ruby-on-rails-3 – 查询中是否为ActiveRecord对象?
发布时间:2020-12-17 02:30:23 所属栏目:百科 来源:网络整理
导读:这是更简洁的写作方式: current_user.products.where(:product_id = product.id).present? 铁轨有类似的东西吗? current_user.products.has? product 我知道我能做到: current_user.products.include? product …但是它会加载所有产品.我正试图从中获得一
这是更简洁的写作方式:
current_user.products.where(:product_id => product.id).present? 铁轨有类似的东西吗? current_user.products.has? product 我知道我能做到: current_user.products.include? product …但是它会加载所有产品.我正试图从中获得一个智能查询. 解决方法
你可以使用存在吗?方法.喜欢:
current_user.products.exists?(product.id) 可能会看看Active Record Query Interface Guide和API. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |