On Jueves, 6 de Mayo de 2010 15:51:31 gs84 escribió: > On 6 mai, 12:34, "Sergio Cambra .:: entreCables S.L. ::." > > <[email protected]> wrote: > > > I have the following associations with 3 classes: Commune, > > > Entiteservice, Offreservice > > > class Commune < ActiveRecord::Base > > > end > > > > > > Commune has 2 attributes: lattitude, longitude > > > > > > ['acos(cos(:lattitude)*cos(entiteservices.commune.lattitue)*cos(entites > > >ervi ces.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' " : > > > > The field is lattitude, not lattitue, and the table is communes, > > entiteservices.commune.lattitude is wrong, change all > > entiteservices.commune with communes, and lattitue with lattitude. You > > only have to set conditions as you would do in where clause of a sql > > query. Anyway, it's cleaner to use geokit plugin than put so much code in > > your controller > > You're right the field is lattitude and i did the correction. > But the relation between Commune and Entiteservice is a many_to_one > relation: > And Commune has_many: entiteservices > Entiteservice belongs_to: commune > > That's why i still get the following error: "Mysql::Error: Unknown > column 'entiteservices.communes.lattitude' in .... "
There is no table entiteservices.communes, but in the query there is a table communes, which is the table with lattitude and longitude columns. That table is joined with communes_offreservices, which is the table for the habtm between offreservices and communes. Check the SQL in log. > 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(entit >eservices.commune.longitude-0.076619951832285)+sin(0.79309216894474)*sin(ent >iteservices.commune.lattitude))*6378.138 < 10)) -- Sergio Cambra .:: entreCables S.L. ::. Mariana Pineda 23, 50.018 Zaragoza T) 902 021 404 F) 976 52 98 07 E) [email protected] -- 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.
