Ruby on Rails Monday, May 30, 2011

Hello,

My database structure consists of Store, Book, BookStore and Address
as below.

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

Now given a book isbn (which is in the Book model) and a store, I need
to find other stores within 5 miles that have that book.

I have looked around but not quite sure how to bring in the Book and
BookStore models with my GeoKit query on something like
Store.within(5, :origin => @storeaddr).

I am on Rails 3.0.5 and using gem 'geokit-rails3'

Appreciate any thoughts/pointers.

-S

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment