【发布时间】:2015-01-20 05:12:14
【问题描述】:
我有三个表,如供应商、位置、技术和两个关联表,如 vendor_location、vendor_technology。
关联如下
vendor.rb
has_many :vendor_technologies
has_many :vendor_locations
has_many :locations, through: :vendor_locations
has_many :technologies, through: :vendor_technologies
位置.rb
has_many :vendor_locations
has_many :vendors, through: :vendor_locations
技术.rb
has_many :vendor_technologies
has_many :vendors, through: :vendor_technologies
vendor_location.rb
belongs_to :location
belongs_to :vendor
vendor_technology.rb
belongs_to :technology
belongs_to :vendor
从上面的表格中,我需要,
1) vendors in locations (india)
need: list of vendors
2) vendors in technology (php)
need: list of vendors
3) vendors in technology and location (php and india)
need: list of vendors
对于上述需求,我需要三个不使用连接操作的单查询。因为,join 占用更多内存(vendor table 有 12 列)
【问题讨论】:
标签: mysql ruby-on-rails ruby ruby-on-rails-3