I have the following associations with 3 classes: Commune,
Entiteservice, Offreservice
class Commune < ActiveRecord::Base
end
Commune has 2 attributes: lattitude, longitude
class Entiteservice < ActiveRecord::Base
belongs_to :commune
has_and_belongs_to_many :offreservices
end
class Offreservice < ActiveRecord::Base
has_and_belongs_to_many :communes
has_and_belongs_to_many :entiteservices
end
In offreservices_controller i have a conditions_for_collection method
to filter the list view. I wanted to list only "Offreservices" witch
"Entiteservice" is in a commune less far than 10 kms from the current
user's commune(City):
def conditions_for_collection
if session[:usager_id] != nil
self.active_scaffold_includes.concat [:communes]
self.active_scaffold_includes.concat [:entiteservices]
commune_usager = Usager.find(session[:usager_id]).commune
#city of the current usager
commune_usager_lat = commune_usager.lattitude #lattitude of
current usager's city
commune_usager_long = commune_usager.longitude #longitude of
current usager's city
['acos(cos(:lattitude)*cos(entiteservices.commune.lattitue)*cos(entiteservices.commune.longitude-:longitude)
+sin(:lattitude)*sin(entiteservices.commune.lattitude))*:r < :max',
{:lattitude => commune_usager_lat, :longitude =>
commune_usager_long,:r => 6378.138, :max => 10}]
end
end
But i am always getting an mysql error "Unknown column
'entiteservices.commune.lattitue' " :
Mysql::Error: Unknown column 'entiteservices.commune.lattitue' in
'where clause': SELECT count(DISTINCT `offreservices`.id) AS count_all
FROM `offreservices` LEFT OUTER JOIN `entiteservices_offreservices`
ON `entiteservices_offreservices`.offreservice_id =
`offreservices`.id LEFT OUTER JOIN `entiteservices` ON
`entiteservices`.id = `entiteservices_offreservices`.entiteservice_id
LEFT OUTER JOIN `offreservices_services` ON
`offreservices_services`.offreservice_id = `offreservices`.id LEFT
OUTER JOIN `services` ON `services`.id =
`offreservices_services`.service_id LEFT OUTER JOIN `horaires` ON
horaires.offreservice_id = offreservices.id LEFT OUTER JOIN
`communes_offreservices` ON `communes_offreservices`.offreservice_id =
`offreservices`.id LEFT OUTER JOIN `communes` ON `communes`.id =
`communes_offreservices`.commune_id WHERE
((acos(cos(0.79309216894474)*cos(entiteservices.commune.lattitue)*cos(entiteservices.commune.longitude-0.076619951832285)+sin(0.79309216894474)*sin(entiteservices.commune.lattitude))*6378.138
< 10))
Can someone help me to solve this problem or if there is another way
to do what i want.
--
You received this message because you are subscribed to the Google Groups
"ActiveScaffold : Ruby on Rails plugin" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/activescaffold?hl=en.