Я чувствую себя немного озадаченным здесь. Ниже приведены несколько примеров кода Rails, сгенерированных соответствующих SQL-запросов и вывода Rails - я использую гем geokit-rails3. В каждом случае, когда я запускаю сгенерированный запрос в окне запроса SQL, я получаю поля, как и следовало ожидать от SQL. Но почему-то эти поля данных не всплывают, поскольку выходные данные из вызова Rails включены ниже.
Казалось бы, какая-то ошибка, но я хочу быть осторожным, так как раньше я упускал из виду очевидные вещи. Учитывая, что порт geokit-rails3 для Rails 3.0 еще не завершен - насколько я понимаю, читая подробности о геме - возможно, это ошибка в этом геме или я что-то упустил?
Я на Rails 3.0.5, Ruby 1.9.2p180 и использую geokit-rails3 gem.
Спасибо за ваши мысли / указатели.
-S
Общий регистр работает нормально - возвращает все записи пользователя
User.joins(:books, :addresses).where("books.isbn = '9780316346627'").within(5, :origin => '100 Spear st, San Francisco, CA')
===> Complete user records
User Load (107.0ms) SELECT `users`.*,
(ACOS(least(1,COS(0.6595974646155383)*COS(-2.13617828468594)*COS(RADIANS(addresses.lat))*COS(RADIANS(addresses.lng))+
COS(0.6595974646155383)*SIN(-2.13617828468594)*COS(RADIANS(addresses.lat))*SIN(RADIANS(addresses.lng))+
SIN(0.6595974646155383)*SIN(RADIANS(addresses.lat))))*3963.19)
AS distance FROM `users` INNER JOIN `book_users` ON `users`.`id` = `book_users`.`user_id` INNER JOIN `books` ON `books`.`id` = `book_users`.`book_id`
INNER JOIN `addresses` ON `addresses`.`user_id` = `users`.`id` WHERE (books.isbn = '9780316346627') AND ((addresses.lat>37.71986597357319 AND address
es.lat<37.8644358264268 AND addresses.lng>-122.48547220806185 AND addresses.lng<-122.30252779193818)) AND ((
(ACOS(least(1,COS(0.6595974646155383)*COS(-2.13617828468594)*COS(RADIANS(addresses.lat))*COS(RADIANS(addresses.lng))+
COS(0.6595974646155383)*SIN(-2.13617828468594)*COS(RADIANS(addresses.lat))*SIN(RADIANS(addresses.lng))+
SIN(0.6595974646155383)*SIN(RADIANS(addresses.lat))))*3963.19)
<= 5))
Получать только электронную почту, когда я должен получать электронную почту, books.id, address.id и distance
User.joins(:books, :addresses).select("users.email as email, books.id as bkid, addresses.id as aid").where("books.isbn = '9780316346627'").within(5, :origin => '100 Spear st, San Francisco, CA')
=> [#<User email: "email1@email.com">, #<User email: "email2@email.net">]
User Load (3.0ms) SELECT users.email as email, books.id as bkid, addresses.id as aid,
(ACOS(least(1,COS(0.6595974646155383)*COS(-2.13617828468594)*COS(RADIANS(addresses.lat))*COS(RADIANS(addresses.lng))+
COS(0.6595974646155383)*SIN(-2.13617828468594)*COS(RADIANS(addresses.lat))*SIN(RADIANS(addresses.lng))+
SIN(0.6595974646155383)*SIN(RADIANS(addresses.lat))))*3963.19)
AS distance FROM `users` INNER JOIN `book_users` ON `users`.`id` = `book_users`.`user_id` INNER JOIN `books` ON `books`.`id` = `book_users`.`book_id`
INNER JOIN `addresses` ON `addresses`.`user_id` = `users`.`id` WHERE (books.isbn = '9780316346627') AND ((addresses.lat>37.71986597357319 AND address
es.lat<37.8644358264268 AND addresses.lng>-122.48547220806185 AND addresses.lng<-122.30252779193818)) AND ((
(ACOS(least(1,COS(0.6595974646155383)*COS(-2.13617828468594)*COS(RADIANS(addresses.lat))*COS(RADIANS(addresses.lng))+
COS(0.6595974646155383)*SIN(-2.13617828468594)*COS(RADIANS(addresses.lat))*SIN(RADIANS(addresses.lng))+
SIN(0.6595974646155383)*SIN(RADIANS(addresses.lat))))*3963.19)
<= 5))
Получите users.id, когда мне нужно получить books.id, address.id и distance
User.joins(:books, :addresses).select("books.id, addresses.id").where("books.isbn = '9780316346627'").within(5, :origin => '100 Spear st, San Francisco, CA')
=> [#<User id: 1>, #<User id: 2>]
User Load (2.0ms) SELECT books.id, addresses.id,
(ACOS(least(1,COS(0.6595974646155383)*COS(-2.13617828468594)*COS(RADIANS(addresses.lat))*COS(RADIANS(addresses.lng))+
COS(0.6595974646155383)*SIN(-2.13617828468594)*COS(RADIANS(addresses.lat))*SIN(RADIANS(addresses.lng))+
SIN(0.6595974646155383)*SIN(RADIANS(addresses.lat))))*3963.19)
AS distance FROM `users` INNER JOIN `book_users` ON `users`.`id` = `book_users`.`user_id` INNER JOIN `books` ON `books`.`id` = `book_users`.`book_id`
INNER JOIN `addresses` ON `addresses`.`user_id` = `users`.`id` WHERE (books.isbn = '9780316346627') AND ((addresses.lat>37.71986597357319 AND address
es.lat<37.8644358264268 AND addresses.lng>-122.48547220806185 AND addresses.lng<-122.30252779193818)) AND ((
(ACOS(least(1,COS(0.6595974646155383)*COS(-2.13617828468594)*COS(RADIANS(addresses.lat))*COS(RADIANS(addresses.lng))+
COS(0.6595974646155383)*SIN(-2.13617828468594)*COS(RADIANS(addresses.lat))*SIN(RADIANS(addresses.lng))+
SIN(0.6595974646155383)*SIN(RADIANS(addresses.lat))))*3963.19)
<= 5))
Ничего не получите, когда я должен получить books.id, address.id и distance
Это то же самое, что и выше, за исключением того, что я назвал поля bkid и aid
User.joins(:books, :addresses).select("books.id as bkid, addresses.id as aid").where("books.isbn = '9780316346627'").within(5, :origin => '100 Spear st, San Francisco, CA')
=> [#<User >, #<User >]
User Load (3.0ms) SELECT books.id as bkid, addresses.id as aid,
(ACOS(least(1,COS(0.6595974646155383)*COS(-2.13617828468594)*COS(RADIANS(addresses.lat))*COS(RADIANS(addresses.lng))+
COS(0.6595974646155383)*SIN(-2.13617828468594)*COS(RADIANS(addresses.lat))*SIN(RADIANS(addresses.lng))+
SIN(0.6595974646155383)*SIN(RADIANS(addresses.lat))))*3963.19)
AS distance FROM `users` INNER JOIN `book_users` ON `users`.`id` = `book_users`.`user_id` INNER JOIN `books` ON `books`.`id` = `book_users`.`book_id`
INNER JOIN `addresses` ON `addresses`.`user_id` = `users`.`id` WHERE (books.isbn = '9780316346627') AND ((addresses.lat>37.71986597357319 AND address
es.lat<37.8644358264268 AND addresses.lng>-122.48547220806185 AND addresses.lng<-122.30252779193818)) AND ((
(ACOS(least(1,COS(0.6595974646155383)*COS(-2.13617828468594)*COS(RADIANS(addresses.lat))*COS(RADIANS(addresses.lng))+
COS(0.6595974646155383)*SIN(-2.13617828468594)*COS(RADIANS(addresses.lat))*SIN(RADIANS(addresses.lng))+
SIN(0.6595974646155383)*SIN(RADIANS(addresses.lat))))*3963.19)
<= 5))
======================= Конечные данные ====================== ===