:order does not work on :include
Posted
by
SpyrosP
on Stack Overflow
See other posts from Stack Overflow
or by SpyrosP
Published on 2010-12-30T02:50:59Z
Indexed on
2010/12/30
2:54 UTC
Read the original article
Hit count: 231
ruby-on-rails
Hello there, i'm wondering why this gives me an error :
DiscoveredLocation.find_all_by_user_id(user.id, :include => [:boss_location, :monsters], :order => 'boss_location.location_index ASC')
It seems as if it's trying to execute a really long query and i get an error like :
Mysql::Error: Unknown column 'monsters_discovered_locations_join.boss_location_id' in 'on clause': SELECT `discovered_locations`.`id` AS t0_r0, `discovered_locations`.`user_id` AS t0_r1, `discovered_locations`.`boss_location_id` AS t0_r2, `discovered_locations`.`created_at` AS t0_r3, `discovered_locations`.`updated_at` AS t0_r4, `boss_locations`.`id` AS t1_r0, `boss_locations`.`name` AS t1_r1, `boss_locations`.`location_index` AS t1_r2, `boss_locations`.`min_level` AS t1_r3, `boss_locations`.`needed_gold_to_open` AS t1_r4, `boss_locations`.`created_at` AS t1_r5, `boss_locations`.`updated_at` AS t1_r6, `monsters`.`id` AS t2_r0, `monsters`.`name` AS t2_r1, `monsters`.`strength` AS t2_r2, `monsters`.`dexterity` AS t2_r3, `monsters`.`magic` AS t2_r4, `monsters`.`accuracy` AS t2_r5, `monsters`.`minGold` AS t2_r6, `monsters`.`maxGold` AS t2_r7, `monsters`.`hp` AS t2_r8, `monsters`.`level` AS t2_r9, `monsters`.`armor` AS t2_r10, `monsters`.`first_class` AS t2_r11, `monsters`.`weapon_id` AS t2_r12, `monsters`.`imageName` AS t2_r13, `monsters`.`monster_type` AS t2_r14, `monsters`.`boss_location_index` AS t2_r15, `monsters`.`boss_location_id` AS t2_r16, `monsters`.`created_at` AS t2_r17, `monsters`.`updated_at` AS t2_r18 FROM `discovered_locations` LEFT OUTER JOIN `boss_locations` ON `boss_locations`.id = `discovered_locations`.boss_location_id LEFT OUTER JOIN `boss_locations` monsters_discovered_locations_join ON (`discovered_locations`.`id` = `monsters_discovered_locations_join`.`boss_location_id`) LEFT OUTER JOIN `monsters` ON (`monsters`.`boss_location_id` = `monsters_discovered_locations_join`.`id`) WHERE (`discovered_locations`.`user_id` = 986759322) ORDER BY boss_location.location_index ASC
The models associations are :
class BossKill < ActiveRecord::Base
belongs_to :user
belongs_to :monster
class DiscoveredLocation < ActiveRecord::Base
belongs_to :user
belongs_to :boss_location
has_many :monsters, :through => :boss_location
has_many :boss_kills, :through => :monsters
class BossLocation < ActiveRecord::Base
has_many :discovered_locations
has_many :users, :through => :discovered_locations
has_many :monsters
Any ideas ?
© Stack Overflow or respective owner