举个例子,我有以下型号:Rails的查找通过协会,地点
class Location < ActiveRecord::Base
attr_accessible :name, :full_address, :latitude, :longitude, :attr1
geocoded_by :full_address
has_many :stores
after_validation :geocode, :if => :full_address_changed?
end
和:
class Store < ActiveRecord::Base
attr_accessible :attr2, :attr3
belongs_to :location
end
我希望能够做的所有存储了搜索的是:
- 都在附近(在位置模型中使用地理编码)
- 遇到一些crite ria on位置模型中的attr1
- 符合Store模型中attr2,attr3的一些条件。
我应该怎么办?
为什么地点与商店有'has_many'关系?难道不是相反吗?如苹果商店的'has_many'位置。除非某个地点是商场或某物,否则我猜这里只有一家商店? – Batkins 2012-01-10 04:16:07
对不起,这个例子有点误导。请在下面看到我对你的答案的解释。 – 2012-01-10 06:30:04