【发布时间】:2013-02-25 17:17:14
【问题描述】:
st = 'pen'
ak = '123123'
agreements = Client.where{authentication_key == ak}.first.agreements
products = Product.joins{agreements}.where{agreements.id.in(a) & (short_description.like(st) | long_description.like( st))}
我正在尝试上述方法,但我的结果集中也需要匹配的协议..
因为这个
class Product < ActiveRecord::Base
has_and_belongs_to_many :agreements, uniq: true
我不能使用 products.first.agreement.first.... 那可能是不同的协议。
【问题讨论】:
-
这是最接近的:Product.joins{agreements}.where{agreements.id.in(a) & (short_description.like(st) | long_description.like(st))}.select{ [agreements.agreement_type, id]} 但我想要的不是 id,而是 product 的所有内容
标签: ruby-on-rails activerecord squeel