2

我的数据库结构由 Store、Book、BookStore 和 Address 组成,如下所示。

class Store < ActiveRecord::Base
  has_many :book_stores
  has_many :books, :through => :book_stores

  has_many :addresses
  acts_as_mappable :through => :addresses
end  

class Address < ActiveRecord::Base
  belongs_to :store
  acts_as_mappable
end  

class Book < ActiveRecord::Base
  has_many :book_stores
  has_many :stores, :through => :book_stores
end  

# Join table for many to many relationship between books and stores
class BookStore < ActiveRecord::Base
  belongs_to :book
  belongs_to :store
end  

现在给定一本书 isbn(在 Book 模型中)和一家商店,我需要找到 5 英里内有这本书的其他商店。

我环顾四周,但不太确定如何使用我的 GeoKit 查询在 Store.within(5, :origin => @storeaddr) 上引入 Book 和 BookStore 模型。

我在 Rails 3.0.5 上并使用 gem 'geokit-rails3'

欣赏任何想法/指针。

-S

4

0 回答 0