sql - Complex Search with Multiple Models and Geokit using Rails -


i attempting make search complicated (of course, make easier users)

i've got app 3 models: campaigns, businesses , locations

like so:

\\ campaign.rb   belongs_to :business   has_many :locations, :through => :business   acts_as_mappable  \\ business.rb   has_many :campaigns   has_many :locations  \\ location.rb   belongs_to :business   has_many :campaigns, :through => :business   acts_as_mappable 

the way set up, there businesses have multiple locations. don't, geokit info coded campaign database entry. have multiple locations geokit info coded location database entry.

i trying search campaigns return results within distance. simple enough when dealing businesses have single address.

  campaign.find(:all,          :conditions => [blahblahblah],        :origin => address,        :within => distance        ) 

however, want include campaigns belong businesses have multiple locations. want search return result campaign, if business has multiple locations, , if of locations fall within bounds. thinking like:

  campaign.find(:all,         :include => [:business, :locations]        :conditions => [blahblahblah],        :origin => address,        :within => distance        ) 

but doesn't return results campaigns belong businesses have multiple locations. i'm noob when comes sql i'm not sure how have rails search in 1 model (campaign), , search across model (the business model) grab results location model. fact geokit involved makes more complex.

i tried: acts_as_mappable :through => :locations in campaign.rb threw sql error

i messed around polymorphic model "addressable" found pretty have start ground on controllers of other models.

i've thought named_scopes believe geokit not support them.

any suggestions?

if think model overly complicated sign needs redesign.

is possible have campaign without business? if not, doesnt make sense make campaign act_as_mappable (im assuming campaign db has lat , lng columns) if business has mappable locations.

if campaign associated business has multiple locations, whats considered location of campaign? store in campaigns.lat , lng attributes?

if youre sticking datamodel, recommend break search multiple commands:

def find_campaigns_near(origin,distance)     locations = location.find(:all,               :origin => address,             :within => distance     );     # use hash uniqueness based on id     campaigns = hash.new     locations.each |location|         location.campaigns.each |campaign|             campaigns[campaign.id] = campaign if campaigns[campaign.id].blank?         end     end     campaigns end 

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -